Skip to content

Commit

Permalink
Add dependency snippet (#209)
Browse files Browse the repository at this point in the history
* Add dependency snippet

* Replace deprecated api calls.
  • Loading branch information
Eskibear authored Jan 3, 2019
1 parent 9ea88a0 commit 41719a6
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/completionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import * as path from "path";
import * as vscode from "vscode";
import Lexx from "xml-zero-lexer";

const dependencySnippet: vscode.SnippetString = new vscode.SnippetString(["<dependency>", "\t<groupId>$1</groupId>", "\t<artifactId>$2</artifactId>", "</dependency>$0"].join("\n"));

class CompletionProvider implements vscode.CompletionItemProvider {
public localRepository: string;
public metadata: {
Expand Down Expand Up @@ -78,6 +80,11 @@ class CompletionProvider implements vscode.CompletionItemProvider {

return this.completeForVersion(document, position, currentNode, groupIdNode.text, artifactIdNode.text);
}
if (currentNode.tag === "dependencies") {
const snippetItem: vscode.CompletionItem = new vscode.CompletionItem("dependency", vscode.CompletionItemKind.Snippet);
snippetItem.insertText = dependencySnippet;
return new vscode.CompletionList([snippetItem], false);
}
return null;
}

Expand All @@ -86,7 +93,8 @@ class CompletionProvider implements vscode.CompletionItemProvider {
const targetRange: vscode.Range = new vscode.Range(document.positionAt(groupIdNode.offset), position);
const groupIdItems: vscode.CompletionItem[] = validGroupIds.map(gid => {
const item: vscode.CompletionItem = new vscode.CompletionItem(gid, vscode.CompletionItemKind.Module);
item.textEdit = new vscode.TextEdit(targetRange, gid);
item.insertText = gid;
item.range = targetRange;
return item;
});
return new vscode.CompletionList(groupIdItems, false);
Expand All @@ -106,7 +114,8 @@ class CompletionProvider implements vscode.CompletionItemProvider {
const targetRange: vscode.Range = new vscode.Range(document.positionAt(artifactIdNode.offset), position);
const artifactIdItems: vscode.CompletionItem[] = validArtifactIds.map(aid => {
const item: vscode.CompletionItem = new vscode.CompletionItem(aid, vscode.CompletionItemKind.Field);
item.textEdit = new vscode.TextEdit(targetRange, aid);
item.insertText = aid;
item.range = targetRange;
return item;
});
return new vscode.CompletionList(artifactIdItems, false);
Expand All @@ -122,7 +131,8 @@ class CompletionProvider implements vscode.CompletionItemProvider {
const targetRange: vscode.Range = new vscode.Range(document.positionAt(versionNode.offset), position);
const versionItems: vscode.CompletionItem[] = validVersions.map(v => {
const item: vscode.CompletionItem = new vscode.CompletionItem(v, vscode.CompletionItemKind.Constant);
item.textEdit = new vscode.TextEdit(targetRange, v);
item.insertText = v;
item.range = targetRange;
return item;
});
return new vscode.CompletionList(versionItems, false);
Expand Down

0 comments on commit 41719a6

Please sign in to comment.