Skip to content

Commit

Permalink
Implement function completion snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
qiuxiang committed Mar 25, 2022
1 parent ff5a3c4 commit 91ff6f2
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/completion/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { ContractDefinition, Identifier } from "solidity-ast";
import { setFlagsFromString } from "v8";
import {
CompletionItem,
CompletionItemKind,
CompletionParams,
CompletionTriggerKind,
InsertTextFormat,
InsertTextMode,
} from "vscode-languageserver";
import { solidityMap } from "..";
import { getDefinitionInfo } from "../hover";
Expand Down Expand Up @@ -111,6 +114,13 @@ function createCompletionItem(node: DefinitionNode) {
item.kind = kindMap.get(node.nodeType);
item.documentation = Reflect.get(node, "documentation")?.text;
item.detail = getDefinitionInfo(node);
if (node.nodeType == "FunctionDefinition") {
const params = node.parameters.parameters
.map((i, index) => `\${${index + 1}:${i.name}}`)
.join(", ");
item.insertText = `${node.name}(${params})`;
item.insertTextFormat = InsertTextFormat.Snippet;
}
return item;
}

Expand Down

0 comments on commit 91ff6f2

Please sign in to comment.