@@ -11,29 +11,49 @@ import {
11
11
createConnection ,
12
12
Diagnostic ,
13
13
DiagnosticSeverity ,
14
+ InitializeParams ,
14
15
Position ,
16
+ ProposedFeatures ,
15
17
Range ,
16
18
TextDocumentEdit ,
17
19
TextDocuments ,
18
20
TextDocumentSyncKind ,
19
21
TextEdit ,
20
22
} from 'vscode-languageserver/node' ;
21
23
import { TextDocument } from 'vscode-languageserver-textdocument' ;
24
+ import { configService } from './services/configuration.service' ;
25
+ import { validateFilePaths } from './validations/validate' ;
22
26
23
- const connection = createConnection ( ) ;
24
- connection . console . info ( `Sample server running in node ${ process . version } ` ) ;
27
+ const connection = createConnection ( ProposedFeatures . all ) ;
28
+
29
+ connection . console . info (
30
+ `CC Language server running in node ${ process . version } `
31
+ ) ;
25
32
26
33
const documents : TextDocuments < TextDocument > = new TextDocuments ( TextDocument ) ;
27
34
documents . listen ( connection ) ;
28
35
29
- connection . onInitialize ( ( ) => {
36
+ connection . onInitialize ( ( params : InitializeParams ) => {
37
+ const capabilities = params . capabilities ;
38
+
39
+ // Does the client support the `workspace/configuration` request?
40
+ // If not, we fall back using global settings.
41
+ configService . hasConfigurationCapability = ! ! (
42
+ capabilities . workspace && ! ! capabilities . workspace . configuration
43
+ ) ;
44
+ configService . hasWorkspaceFolderCapability = ! ! (
45
+ capabilities . workspace && ! ! capabilities . workspace . workspaceFolders
46
+ ) ;
47
+ configService . hasDiagnosticRelatedInformationCapability =
48
+ ! ! capabilities . textDocument ?. publishDiagnostics ?. relatedInformation ;
49
+
30
50
return {
31
51
capabilities : {
32
52
// codeActionProvider: true,
33
- // textDocumentSync: {
34
- // openClose: true,
35
- // change: TextDocumentSyncKind.Incremental,
36
- // },
53
+ textDocumentSync : {
54
+ openClose : true ,
55
+ change : TextDocumentSyncKind . Incremental ,
56
+ } ,
37
57
// executeCommandProvider: {
38
58
// commands: ['sample.fixMe'],
39
59
// },
@@ -42,53 +62,52 @@ connection.onInitialize(() => {
42
62
} ) ;
43
63
44
64
function validate ( document : TextDocument ) : void {
65
+ const diagnostics = validateFilePaths ( document ) ;
66
+
45
67
connection . sendDiagnostics ( {
46
68
uri : document . uri ,
47
69
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
- ] ,
70
+ diagnostics,
55
71
} ) ;
56
72
}
57
73
58
- // documents.onDidOpen((event) => {
59
- // validate(event.document);
60
- // });
61
-
62
- // documents.onDidChangeContent((event) => {
63
- // validate(event.document);
64
- // });
74
+ documents . onDidOpen ( ( event ) => {
75
+ validate ( event . document ) ;
76
+ } ) ;
65
77
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
- // });
78
+ documents . onDidChangeContent ( ( event ) => {
79
+ validate ( event . document ) ;
80
+ } ) ;
74
81
75
- // connection.onExecuteCommand(async (params) => {
76
- // if (params.command !== 'sample.fixMe' || params.arguments === undefined) {
77
- // return;
78
- // }
82
+ /*
83
+ connection.onCodeAction((params) => {
84
+ const textDocument = documents.get(params.textDocument.uri);
85
+ if (textDocument === undefined) {
86
+ return undefined;
87
+ }
88
+ const title = 'With User Input';
89
+ return [CodeAction.create(title, Command.create(title, 'sample.fixMe', textDocument.uri), CodeActionKind.QuickFix)];
90
+ });
91
+ */
79
92
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
- // });
93
+ /*
94
+ connection.onExecuteCommand(async (params) => {
95
+ if (params.command !== 'sample.fixMe' || params.arguments === undefined) {
96
+ return;
97
+ }
93
98
99
+ const textDocument = documents.get(params.arguments[0]);
100
+ if (textDocument === undefined) {
101
+ return;
102
+ }
103
+ const newText = typeof params.arguments[1] === 'string' ? params.arguments[1] : 'Eclipse';
104
+ connection.workspace.applyEdit({
105
+ documentChanges: [
106
+ TextDocumentEdit.create({ uri: textDocument.uri, version: textDocument.version }, [
107
+ TextEdit.insert(Position.create(0, 0), newText)
108
+ ])
109
+ ]
110
+ });
111
+ });
112
+ */
94
113
connection . listen ( ) ;
0 commit comments