mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-04-27 16:55:44 +08:00
Adding SnippetString-based completion sample which demonstrates how dynamic context-sensitive snippets can be created.
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "completions-sample",
|
||||
"displayName": "Completion Item Provider Sample",
|
||||
"version": "0.0.1",
|
||||
"version": "0.0.2",
|
||||
"publisher": "jrieken",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -11,7 +11,7 @@
|
||||
"url": "https://github.com/Microsoft/vscode-extension-samples/issues"
|
||||
},
|
||||
"engines": {
|
||||
"vscode": "^1.5.0"
|
||||
"vscode": "^1.18.0"
|
||||
},
|
||||
"categories": [
|
||||
"Other"
|
||||
@ -20,9 +20,15 @@
|
||||
"*"
|
||||
],
|
||||
"main": "./out/extension",
|
||||
"scripts": {
|
||||
"vscode:prepublish": "tsc -p ./",
|
||||
"compile": "tsc -watch -p ./",
|
||||
"postinstall": "node ./node_modules/vscode/bin/install",
|
||||
"tslint": "tslint -c tslint.json src/extension.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^2.1.4",
|
||||
"vscode": "^1.0.0",
|
||||
"vscode": "^1.1.10",
|
||||
"@types/node": "^6.0.40"
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,10 +10,30 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
|
||||
// The most simple completion item provider which
|
||||
// * registers for text files (`'plaintext'`), and
|
||||
// * only return the 'Hello World' completion
|
||||
// * return the 'Hello World' and
|
||||
// a snippet-based completion item.
|
||||
vscode.languages.registerCompletionItemProvider('plaintext', {
|
||||
provideCompletionItems() {
|
||||
return [new vscode.CompletionItem('Hello World')];
|
||||
return [
|
||||
new vscode.CompletionItem('Hello World!'),
|
||||
createSnippetItem()
|
||||
];
|
||||
}
|
||||
});
|
||||
|
||||
function createSnippetItem(): vscode.CompletionItem {
|
||||
|
||||
// Read more here:
|
||||
// https://code.visualstudio.com/docs/extensionAPI/vscode-api#CompletionItem
|
||||
// https://code.visualstudio.com/docs/extensionAPI/vscode-api#SnippetString
|
||||
|
||||
// For SnippetString syntax look here:
|
||||
// https://code.visualstudio.com/docs/editor/userdefinedsnippets#_creating-your-own-snippets
|
||||
|
||||
let item = new vscode.CompletionItem('Good part of the day', vscode.CompletionItemKind.Snippet);
|
||||
item.insertText = new vscode.SnippetString("Good ${1|morning,afternoon,evening|}.");
|
||||
item.documentation = new vscode.MarkdownString("Inserts a snippet that lets you select the _appropriate_ part of the day for your greeting.");
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,8 +20,8 @@ let documents: TextDocuments = new TextDocuments();
|
||||
// for open, change and close text document events
|
||||
documents.listen(connection);
|
||||
|
||||
// After the server has started the client sends an initilize request. The server receives
|
||||
// in the passed params the rootPath of the workspace plus the client capabilites.
|
||||
// After the server has started the client sends an initialize request. The server receives
|
||||
// in the passed params the rootPath of the workspace plus the client capabilities.
|
||||
let workspaceRoot: string;
|
||||
connection.onInitialize((params): InitializeResult => {
|
||||
workspaceRoot = params.rootPath;
|
||||
@ -91,7 +91,7 @@ function validateTextDocument(textDocument: TextDocument): void {
|
||||
|
||||
connection.onDidChangeWatchedFiles((_change) => {
|
||||
// Monitored files have change in VSCode
|
||||
connection.console.log('We recevied an file change event');
|
||||
connection.console.log('We received an file change event');
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -61,7 +61,7 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
}
|
||||
</style>
|
||||
<body>
|
||||
<div>Preview of the <a href="${encodeURI('command:extension.revealCssRule?' + JSON.stringify([document.uri, propStart, propEnd]))}">CSS properties</a></dev>
|
||||
<div>Preview of the <a href="${encodeURI('command:extension.revealCssRule?' + JSON.stringify([document.uri, propStart, propEnd]))}">CSS properties</a></div>
|
||||
<hr>
|
||||
<div id="el">Lorem ipsum dolor sit amet, mi et mauris nec ac luctus lorem, proin leo nulla integer metus vestibulum lobortis, eget</div>
|
||||
</body>`;
|
||||
|
||||
Reference in New Issue
Block a user