8
8
/// <reference path="../node_modules/@types/node/index.d.ts" />
9
9
10
10
import {
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
16
16
} from 'vscode-languageserver' ;
17
17
18
18
import { TextDocuments , TextDocumentEvent } from './documents' ;
@@ -31,12 +31,12 @@ let documents: TextDocuments = new TextDocuments(handleTextEvent);
31
31
const errorCollector = new ErrorCollector ( documents , connection ) ;
32
32
33
33
function 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
+ }
40
40
}
41
41
42
42
// Make the text document manager listen on the connection
@@ -47,45 +47,45 @@ documents.listen(connection);
47
47
// in the passed params the rootPath of the workspace plus the client capabilites.
48
48
let workspaceRoot : string ;
49
49
connection . 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
+ }
62
62
} ) ;
63
63
64
64
function 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 ;
72
72
}
73
73
74
74
// This handler provides the initial list of the completion items.
75
75
connection . 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
+ }
89
89
} ) ;
90
90
91
91
0 commit comments