5
5
'use strict' ;
6
6
7
7
import {
8
- CodeAction , CodeActionKind , Command , createConnection , Diagnostic , DiagnosticSeverity , Position , Range , TextDocumentEdit ,
9
- TextDocuments , TextDocumentSyncKind , TextEdit
8
+ CodeAction ,
9
+ CodeActionKind ,
10
+ Command ,
11
+ createConnection ,
12
+ Diagnostic ,
13
+ DiagnosticSeverity ,
14
+ Position ,
15
+ Range ,
16
+ TextDocumentEdit ,
17
+ TextDocuments ,
18
+ TextDocumentSyncKind ,
19
+ TextEdit ,
10
20
} from 'vscode-languageserver/node' ;
11
21
import { TextDocument } from 'vscode-languageserver-textdocument' ;
12
22
@@ -17,64 +27,68 @@ const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);
17
27
documents . listen ( connection ) ;
18
28
19
29
connection . onInitialize ( ( ) => {
20
- return {
21
- capabilities : {
22
- codeActionProvider : true ,
23
- textDocumentSync : {
24
- openClose : true ,
25
- change : TextDocumentSyncKind . Incremental
26
- } ,
27
- executeCommandProvider : {
28
- commands : [ 'sample.fixMe' ]
29
- }
30
- }
31
- } ;
30
+ return {
31
+ capabilities : {
32
+ codeActionProvider : true ,
33
+ textDocumentSync : {
34
+ openClose : true ,
35
+ change : TextDocumentSyncKind . Incremental ,
36
+ } ,
37
+ executeCommandProvider : {
38
+ commands : [ 'sample.fixMe' ] ,
39
+ } ,
40
+ } ,
41
+ } ;
32
42
} ) ;
33
43
34
44
function validate ( document : TextDocument ) : void {
35
- connection . sendDiagnostics ( {
36
- uri : document . uri ,
37
- version : document . version ,
38
- diagnostics : [
39
- Diagnostic . create ( Range . create ( 0 , 0 , 0 , 10 ) , 'Something is wrong here' , DiagnosticSeverity . Warning )
40
- ]
41
- } ) ;
45
+ connection . sendDiagnostics ( {
46
+ uri : document . uri ,
47
+ version : document . version ,
48
+ diagnostics : [
49
+ Diagnostic . create (
50
+ Range . create ( 0 , 0 , 0 , 10 ) ,
51
+ 'Something is wrong here' ,
52
+ DiagnosticSeverity . Warning
53
+ ) ,
54
+ ] ,
55
+ } ) ;
42
56
}
43
57
44
58
documents . onDidOpen ( ( event ) => {
45
- validate ( event . document ) ;
59
+ validate ( event . document ) ;
46
60
} ) ;
47
61
48
62
documents . onDidChangeContent ( ( event ) => {
49
- validate ( event . document ) ;
63
+ validate ( event . document ) ;
50
64
} ) ;
51
65
52
- connection . onCodeAction ( ( params ) => {
53
- const textDocument = documents . get ( params . textDocument . uri ) ;
54
- if ( textDocument === undefined ) {
55
- return undefined ;
56
- }
57
- const title = 'With User Input' ;
58
- return [ CodeAction . create ( title , Command . create ( title , 'sample.fixMe' , textDocument . uri ) , CodeActionKind . QuickFix ) ] ;
59
- } ) ;
66
+ // connection.onCodeAction((params) => {
67
+ // const textDocument = documents.get(params.textDocument.uri);
68
+ // if (textDocument === undefined) {
69
+ // return undefined;
70
+ // }
71
+ // const title = 'With User Input';
72
+ // return [CodeAction.create(title, Command.create(title, 'sample.fixMe', textDocument.uri), CodeActionKind.QuickFix)];
73
+ // });
60
74
61
- connection . onExecuteCommand ( async ( params ) => {
62
- if ( params . command !== 'sample.fixMe' || params . arguments === undefined ) {
63
- return ;
64
- }
75
+ // connection.onExecuteCommand(async (params) => {
76
+ // if (params.command !== 'sample.fixMe' || params.arguments === undefined) {
77
+ // return;
78
+ // }
65
79
66
- const textDocument = documents . get ( params . arguments [ 0 ] ) ;
67
- if ( textDocument === undefined ) {
68
- return ;
69
- }
70
- const newText = typeof params . arguments [ 1 ] === 'string' ? params . arguments [ 1 ] : 'Eclipse' ;
71
- connection . workspace . applyEdit ( {
72
- documentChanges : [
73
- TextDocumentEdit . create ( { uri : textDocument . uri , version : textDocument . version } , [
74
- TextEdit . insert ( Position . create ( 0 , 0 ) , newText )
75
- ] )
76
- ]
77
- } ) ;
78
- } ) ;
80
+ // const textDocument = documents.get(params.arguments[0]);
81
+ // if (textDocument === undefined) {
82
+ // return;
83
+ // }
84
+ // const newText = typeof params.arguments[1] === 'string' ? params.arguments[1] : 'Eclipse';
85
+ // connection.workspace.applyEdit({
86
+ // documentChanges: [
87
+ // TextDocumentEdit.create({ uri: textDocument.uri, version: textDocument.version }, [
88
+ // TextEdit.insert(Position.create(0, 0), newText)
89
+ // ])
90
+ // ]
91
+ // });
92
+ // });
79
93
80
94
connection . listen ( ) ;
0 commit comments