@@ -28,6 +28,38 @@ import * as ic from "./incrementalCompilation";
28
28
import config , { extensionConfiguration } from "./config" ;
29
29
import { projectsFiles } from "./projectFiles" ;
30
30
31
+ const notificationLevelMap = new Map ( [
32
+ [ "error" , p . MessageType . Error ] ,
33
+ [ "warning" , p . MessageType . Warning ] ,
34
+ [ "info" , p . MessageType . Info ] ,
35
+ [ "log" , p . MessageType . Log ]
36
+ ] )
37
+
38
+ /**
39
+ * Sends an LSP log notification that will appear in the ReScript Language Server Output window in VSCode.
40
+ * Other LSP clients will also receive this notification,
41
+ * as we utilize LanguageClient in the VSCode extension, providing this functionality at no extra cost.
42
+ */
43
+ function sendLogNotification ( level : p . MessageType , message : string ) {
44
+ const currentLogLevel = notificationLevelMap . get ( config . extensionConfiguration . logLevel ) || p . MessageType . Info ;
45
+
46
+ if ( currentLogLevel >= level ) {
47
+ const logMessageParams : p . LogMessageParams = {
48
+ type : level ,
49
+ message
50
+ }
51
+ const notificationMessage : p . NotificationMessage = {
52
+ method : "window/logMessage" ,
53
+ jsonrpc : c . jsonrpcVersion ,
54
+ params : logMessageParams
55
+ }
56
+
57
+ if ( send ) {
58
+ send ( notificationMessage ) ;
59
+ }
60
+ }
61
+ }
62
+
31
63
// This holds client capabilities specific to our extension, and not necessarily
32
64
// related to the LS protocol. It's for enabling/disabling features that might
33
65
// work in one client, like VSCode, but perhaps not in others, like vim.
@@ -55,18 +87,18 @@ let stupidFileContentCache: Map<string, string> = new Map();
55
87
let codeActionsFromDiagnostics : codeActions . filesCodeActions = { } ;
56
88
57
89
// will be properly defined later depending on the mode (stdio/node-rpc)
58
- let send : ( msg : p . Message ) => void = ( _ ) => { } ;
90
+ let send : ( msg : p . Message ) => void = ( _ ) => { } ;
59
91
60
92
let findRescriptBinary = ( projectRootPath : p . DocumentUri | null ) =>
61
93
config . extensionConfiguration . binaryPath == null
62
94
? lookup . findFilePathFromProjectRoot (
63
- projectRootPath ,
64
- path . join ( c . nodeModulesBinDir , c . rescriptBinName )
65
- )
95
+ projectRootPath ,
96
+ path . join ( c . nodeModulesBinDir , c . rescriptBinName )
97
+ )
66
98
: utils . findBinary (
67
- config . extensionConfiguration . binaryPath ,
68
- c . rescriptBinName
69
- ) ;
99
+ config . extensionConfiguration . binaryPath ,
100
+ c . rescriptBinName
101
+ ) ;
70
102
71
103
let createInterfaceRequest = new v . RequestType <
72
104
p . TextDocumentIdentifier ,
@@ -333,9 +365,9 @@ let openedFile = (fileUri: string, fileContent: string) => {
333
365
message :
334
366
config . extensionConfiguration . binaryPath == null
335
367
? `Can't find ReScript binary in ${ path . join (
336
- projectRootPath ,
337
- c . nodeModulesBinDir
338
- ) } or parent directories. Did you install it? It's required to use "rescript" > 9.1`
368
+ projectRootPath ,
369
+ c . nodeModulesBinDir
370
+ ) } or parent directories. Did you install it? It's required to use "rescript" > 9.1`
339
371
: `Can't find ReScript binary in the directory ${ config . extensionConfiguration . binaryPath } ` ,
340
372
} ,
341
373
} ;
@@ -419,6 +451,7 @@ export default function listen(useStdio = false) {
419
451
send = ( msg : p . Message ) => process . send ! ( msg ) ;
420
452
process . on ( "message" , onMessage ) ;
421
453
}
454
+ utils . setSendLogNotification ( sendLogNotification ) ;
422
455
}
423
456
424
457
function hover ( msg : p . RequestMessage ) {
@@ -1183,15 +1216,15 @@ function onMessage(msg: p.Message) {
1183
1216
inlayHintProvider : config . extensionConfiguration . inlayHints ?. enable ,
1184
1217
codeLensProvider : config . extensionConfiguration . codeLens
1185
1218
? {
1186
- workDoneProgress : false ,
1187
- }
1219
+ workDoneProgress : false ,
1220
+ }
1188
1221
: undefined ,
1189
1222
signatureHelpProvider : config . extensionConfiguration . signatureHelp
1190
1223
?. enabled
1191
1224
? {
1192
- triggerCharacters : [ "(" ] ,
1193
- retriggerCharacters : [ "=" , "," ] ,
1194
- }
1225
+ triggerCharacters : [ "(" ] ,
1226
+ retriggerCharacters : [ "=" , "," ] ,
1227
+ }
1195
1228
: undefined ,
1196
1229
} ,
1197
1230
} ;
@@ -1202,6 +1235,8 @@ function onMessage(msg: p.Message) {
1202
1235
} ;
1203
1236
initialized = true ;
1204
1237
1238
+ sendLogNotification ( p . MessageType . Info , `LSP Server started!` )
1239
+
1205
1240
// Periodically pull configuration from the client.
1206
1241
pullConfigurationPeriodically = setInterval ( ( ) => {
1207
1242
askForAllCurrentConfiguration ( ) ;
0 commit comments