|
6 | 6 |
|
7 | 7 | import * as path from 'path'; |
8 | 8 |
|
9 | | -import { languages, window, commands, ExtensionContext, TextDocument, ColorInformation, ColorPresentation, Color } from 'vscode'; |
10 | | -import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, TextEdit } from 'vscode-languageclient'; |
| 9 | +import { languages, window, commands, ExtensionContext, TextDocument, ColorInformation, ColorPresentation, Color, Range, Position, CompletionItem, CompletionItemKind, TextEdit, SnippetString } from 'vscode'; |
| 10 | +import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'vscode-languageclient'; |
11 | 11 |
|
12 | 12 | import { ConfigurationFeature } from 'vscode-languageclient/lib/configuration.proposed'; |
13 | 13 | import { DocumentColorRequest, DocumentColorParams, ColorPresentationRequest, ColorPresentationParams } from 'vscode-languageserver-protocol/lib/protocol.colorProvider.proposed'; |
@@ -104,6 +104,31 @@ export function activate(context: ExtensionContext) { |
104 | 104 | indentationRules: indentationRules |
105 | 105 | }); |
106 | 106 |
|
| 107 | + const regionCompletionRegExpr = /^(\s*)(\/(\*\s*(#\w*)?)?)?/; |
| 108 | + languages.registerCompletionItemProvider(documentSelector, { |
| 109 | + provideCompletionItems(doc, pos) { |
| 110 | + let lineUntilPos = doc.getText(new Range(new Position(pos.line, 0), pos)); |
| 111 | + let match = lineUntilPos.match(regionCompletionRegExpr); |
| 112 | + if (match) { |
| 113 | + let range = new Range(new Position(pos.line, match[1].length), pos); |
| 114 | + let beginProposal = new CompletionItem('#region', CompletionItemKind.Snippet); |
| 115 | + beginProposal.range = range; TextEdit.replace(range, '/* #region */'); |
| 116 | + beginProposal.insertText = new SnippetString('/* #region $1*/'); |
| 117 | + beginProposal.documentation = localize('folding.start', 'Folding Region Start'); |
| 118 | + beginProposal.filterText = match[2]; |
| 119 | + beginProposal.sortText = 'za'; |
| 120 | + let endProposal = new CompletionItem('#endregion', CompletionItemKind.Snippet); |
| 121 | + endProposal.range = range; |
| 122 | + endProposal.insertText = '/* #endregion */'; |
| 123 | + endProposal.documentation = localize('folding.end', 'Folding Region End'); |
| 124 | + endProposal.sortText = 'zb'; |
| 125 | + endProposal.filterText = match[2]; |
| 126 | + return [beginProposal, endProposal]; |
| 127 | + } |
| 128 | + return null; |
| 129 | + } |
| 130 | + }); |
| 131 | + |
107 | 132 | commands.registerCommand('_css.applyCodeAction', applyCodeAction); |
108 | 133 |
|
109 | 134 | function applyCodeAction(uri: string, documentVersion: number, edits: TextEdit[]) { |
|
0 commit comments