88/// <reference path="../node_modules/@types/node/index.d.ts" />
99
1010import {
11- IPCMessageReader , IPCMessageWriter ,
12- createConnection , IConnection , TextDocumentSyncKind ,
13- TextDocument , Diagnostic , DiagnosticSeverity ,
14- InitializeParams , InitializeResult , TextDocumentPositionParams ,
15- CompletionItem , CompletionItemKind , TextDocumentIdentifier , Range
11+ IPCMessageReader , IPCMessageWriter ,
12+ createConnection , IConnection , TextDocumentSyncKind ,
13+ TextDocument , Diagnostic , DiagnosticSeverity ,
14+ InitializeParams , InitializeResult , TextDocumentPositionParams ,
15+ CompletionItem , CompletionItemKind , TextDocumentIdentifier , Range
1616} from 'vscode-languageserver' ;
1717
1818import { TextDocuments , TextDocumentEvent } from './documents' ;
@@ -31,12 +31,12 @@ let documents: TextDocuments = new TextDocuments(handleTextEvent);
3131const errorCollector = new ErrorCollector ( documents , connection ) ;
3232
3333function handleTextEvent ( event : TextDocumentEvent ) {
34- switch ( event . kind ) {
35- case 'context' :
36- case 'change' :
37- case 'opened' :
38- errorCollector . requestErrors ( event . document ) ;
39- }
34+ switch ( event . kind ) {
35+ case 'context' :
36+ case 'change' :
37+ case 'opened' :
38+ errorCollector . requestErrors ( event . document ) ;
39+ }
4040}
4141
4242// Make the text document manager listen on the connection
@@ -47,45 +47,45 @@ documents.listen(connection);
4747// in the passed params the rootPath of the workspace plus the client capabilites.
4848let workspaceRoot : string ;
4949connection . onInitialize ( ( params ) : InitializeResult => {
50- workspaceRoot = params . rootPath ;
51- return {
52- capabilities : {
53- // Tell the client that the server works in FULL text document sync mode
54- textDocumentSync : documents . syncKind ,
55- // Tell the client that the server support code complete
56- completionProvider : {
57- resolveProvider : false ,
58- triggerCharacters : [ '<' , '.' ]
59- }
60- }
61- }
50+ workspaceRoot = params . rootPath ;
51+ return {
52+ capabilities : {
53+ // Tell the client that the server works in FULL text document sync mode
54+ textDocumentSync : documents . syncKind ,
55+ // Tell the client that the server support code complete
56+ completionProvider : {
57+ resolveProvider : false ,
58+ triggerCharacters : [ '<' , '.' ]
59+ }
60+ }
61+ }
6262} ) ;
6363
6464function compiletionKindToCompletionItemKind ( kind : string ) : number {
65- switch ( kind ) {
66- case 'element' : return CompletionItemKind . Class ;
67- case 'attribute' : return CompletionItemKind . Field ;
68- case 'entity' : return CompletionItemKind . Text ;
69- case 'member' : return CompletionItemKind . Property ;
70- }
71- return CompletionItemKind . Text ;
65+ switch ( kind ) {
66+ case 'element' : return CompletionItemKind . Class ;
67+ case 'attribute' : return CompletionItemKind . Field ;
68+ case 'entity' : return CompletionItemKind . Text ;
69+ case 'member' : return CompletionItemKind . Property ;
70+ }
71+ return CompletionItemKind . Text ;
7272}
7373
7474// This handler provides the initial list of the completion items.
7575connection . onCompletion ( ( textDocumentPosition : TextDocumentPositionParams ) : CompletionItem [ ] => {
76- const { fileName, service, offset} = documents . getServiceInfo ( textDocumentPosition . textDocument ,
77- textDocumentPosition . position )
78- if ( service ) {
79- const result = service . getCompletionsAt ( fileName , offset ) ;
80- if ( result ) {
81- return result . map ( completion => ( {
82- label : completion . name ,
83- kind : compiletionKindToCompletionItemKind ( completion . kind ) ,
84- detail : completion . kind ,
85- sortText : completion . sort
86- } ) ) ;
87- }
88- }
76+ const { fileName, service, offset} = documents . getServiceInfo ( textDocumentPosition . textDocument ,
77+ textDocumentPosition . position )
78+ if ( service ) {
79+ const result = service . getCompletionsAt ( fileName , offset ) ;
80+ if ( result ) {
81+ return result . map ( completion => ( {
82+ label : completion . name ,
83+ kind : compiletionKindToCompletionItemKind ( completion . kind ) ,
84+ detail : completion . kind ,
85+ sortText : completion . sort
86+ } ) ) ;
87+ }
88+ }
8989} ) ;
9090
9191
0 commit comments