Skip to content

Commit 8cfcb51

Browse files
nikolightsaberNikolai Devolder
and
Nikolai Devolder
authored
fix(logging): Reduce startup notifications by using "window/logMessage" (#217)
Problem: The server pushes a lot of notifications to the client using "window/showMessage". All messages are pure informational. Fix: use "window/logMessage" for all messages that are not errors, Still use "window/showMessage" for errors and exceptions Co-authored-by: Nikolai Devolder <[email protected]>
1 parent 40be7dd commit 8cfcb51

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

Diff for: src/CSharpLanguageServer/Handlers/Initialization.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module Initialization =
2626
(p: InitializeParams)
2727
: Async<LspResult<InitializeResult>> = async {
2828
// context.State.LspClient has not been initialized yet thus context.WindowShowMessage will not work
29-
let windowShowMessage m = lspClient.WindowShowMessage({ Type = MessageType.Info; Message = m })
29+
let windowShowMessage m = lspClient.WindowLogMessage({ Type = MessageType.Info; Message = m })
3030

3131
context.Emit(ClientChange (Some lspClient))
3232

Diff for: src/CSharpLanguageServer/RoslynHelpers.fs

+20-14
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,12 @@ let tryLoadSolutionOnPath
378378
solutionPath =
379379
let progress = ProgressReporter(lspClient)
380380

381+
let logMessage m =
382+
lspClient.WindowLogMessage({
383+
Type = MessageType.Info
384+
Message = sprintf "csharp-ls: %s" m
385+
})
386+
381387
let showMessage m =
382388
lspClient.WindowShowMessage({
383389
Type = MessageType.Info
@@ -388,7 +394,7 @@ let tryLoadSolutionOnPath
388394
try
389395
let beginMessage = sprintf "Loading solution \"%s\"..." solutionPath
390396
do! progress.Begin(beginMessage)
391-
do! showMessage beginMessage
397+
do! logMessage beginMessage
392398

393399
let msbuildWorkspace = MSBuildWorkspace.Create(CSharpLspHostServices())
394400
msbuildWorkspace.LoadMetadataForReferencedProjects <- true
@@ -401,11 +407,11 @@ let tryLoadSolutionOnPath
401407
>> Log.addContext "message" (diag.ToString())
402408
)
403409

404-
do! showMessage (sprintf "msbuildWorkspace.Diagnostics: %s" (diag.ToString()))
410+
do! logMessage (sprintf "msbuildWorkspace.Diagnostics: %s" (diag.ToString()))
405411

406412
let endMessage = sprintf "Finished loading solution \"%s\"" solutionPath
407413
do! progress.End endMessage
408-
do! showMessage endMessage
414+
do! logMessage endMessage
409415

410416
return Some solution
411417
with
@@ -419,7 +425,7 @@ let tryLoadSolutionOnPath
419425
let tryLoadSolutionFromProjectFiles
420426
(lspClient: ILspClient)
421427
(logger: ILog)
422-
(showMessage: string -> Async<unit>)
428+
(logMessage: string -> Async<unit>)
423429
(projs: string list) =
424430
let progress = ProgressReporter(lspClient)
425431

@@ -431,7 +437,7 @@ let tryLoadSolutionFromProjectFiles
431437
msbuildWorkspace.LoadMetadataForReferencedProjects <- true
432438
for file in projs do
433439
if projs.Length < 10 then
434-
do! showMessage (sprintf "loading project \"%s\".." file)
440+
do! logMessage (sprintf "loading project \"%s\".." file)
435441
try
436442
do! msbuildWorkspace.OpenProjectAsync(file) |> Async.AwaitTask |> Async.Ignore
437443
with ex ->
@@ -473,13 +479,13 @@ let findAndLoadSolutionOnDir
473479
|> Seq.filter fileNotOnNodeModules
474480
|> Seq.toList
475481

476-
let showMessage m =
477-
lspClient.WindowShowMessage({
482+
let logMessage m =
483+
lspClient.WindowLogMessage({
478484
Type = MessageType.Info
479485
Message = sprintf "csharp-ls: %s" m
480486
})
481487

482-
do! showMessage (sprintf "%d solution(s) found: [%s]" solutionFiles.Length (String.Join(", ", solutionFiles)) )
488+
do! logMessage (sprintf "%d solution(s) found: [%s]" solutionFiles.Length (String.Join(", ", solutionFiles)) )
483489

484490
let singleSolutionFound =
485491
match solutionFiles with
@@ -488,8 +494,8 @@ let findAndLoadSolutionOnDir
488494

489495
match singleSolutionFound with
490496
| None ->
491-
do! showMessage ("no or multiple .sln files found on " + dir)
492-
do! showMessage ("looking for .csproj/fsproj files on " + dir + "..")
497+
do! logMessage ("no or multiple .sln files found on " + dir)
498+
do! logMessage ("looking for .csproj/fsproj files on " + dir + "..")
493499

494500
let projFiles =
495501
let csprojFiles = Directory.GetFiles(dir, "*.csproj", SearchOption.AllDirectories)
@@ -501,10 +507,10 @@ let findAndLoadSolutionOnDir
501507

502508
if projFiles.Length = 0 then
503509
let message = "no or .csproj/.fsproj or sln files found on " + dir
504-
do! showMessage message
510+
do! logMessage message
505511
Exception message |> raise
506512

507-
return! tryLoadSolutionFromProjectFiles lspClient logger showMessage projFiles
513+
return! tryLoadSolutionFromProjectFiles lspClient logger logMessage projFiles
508514

509515
| Some solutionPath ->
510516
return! tryLoadSolutionOnPath lspClient logger solutionPath
@@ -521,12 +527,12 @@ let loadSolutionOnSolutionPathOrDir
521527
}
522528

523529
| None -> async {
524-
let logMessage: ShowMessageParams = {
530+
let logMessage: LogMessageParams = {
525531
Type = MessageType.Info
526532
Message = sprintf "csharp-ls: attempting to find and load solution based on root path (\"%s\").." rootPath
527533
}
528534

529-
do! lspClient.WindowShowMessage(logMessage)
535+
do! lspClient.WindowLogMessage(logMessage)
530536
return! findAndLoadSolutionOnDir lspClient logger rootPath
531537
}
532538

0 commit comments

Comments
 (0)