Conversation
clientInfo is optional in the LSP spec and TClientInfo.version is not auto-created; accessing them without a check crashed the server on initialize from minimal clients that omit clientInfo.
In ParseSource the except branch passed the filename through "with FParser.CurSourcePos do", whose FileName field is empty for scanner errors (e.g. include file not found, fired before the parser advanced). The empty record field shadowed the filled local Filename, so the diagnostic was published with a broken "file:" URI and clients dropped it - the file looked like it never got any diagnostics. - ParseSource except: drop the with-statement, pass the local Filename - DoError: fall back to the buffer filename when CurSourcePos.FileName is empty (same scanner-error case)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Diagnostics for scanner errors were published with a broken URI
Two independent fixes found while running pasls against mixed Delphi/FPC
projects, both reproduced with plain LSP clients (no editor).
1. Guard optional
clientInfoinShowConfigStatusclientInfois optional in the LSP spec andTClientInfo.versionis notauto-created. A minimal client that omits
clientInfocrashed the serverright on
initialize. Now both are checked; the client line logs as[unspecified]when absent.2. Empty filename in diagnostics for scanner errors
Symptom: for files whose first error comes from the scanner (e.g.
{$I ../../x.inc}that cannot be resolved →EScannerError, error code 1003),the client never received any
publishDiagnostics— the file silently looked"clean or dead", while stderr showed the error.
Root cause: in
TSourceParser.ParseSourcethe except branch passed thefilename through
For scanner errors the parser never advanced, so
CurSourcePosis still(Row=0, Column=0, FileName='')— and its emptyFileNameshadowed thefilled local
Filename. The diagnostic ended up inTPublishDiagnostics.Add(fileName='')→uri = 'file:', which no client canmatch to a document, so the publish was dropped.
Fixes:
ParseSourceexcept: drop the with-statement, pass the localFilenameexplicitly, read
Row/Columndirectly fromCurSourcePos.DoError(multi-error path): same shadowing pattern — fall back to thebuffer filename when
CurSourcePos.FileNameis empty.Result: scanner errors (unresolvable includes, etc.) are now reported with a
valid document URI instead of being silently dropped.
Related upstream fixes
While testing pasls diagnostics, two parser bugs in its dependencies were found
and fixed upstream:
(e.g.
strict private constwith no constants, or an{$IFDEF}-gutted one)broke
TPasParserwithExpected "=", soStrictSyntaxCheckfailed onvalid units —
https://gitlab.com/freepascal.org/fpc/source/-/merge_requests/1567
(
{$IFDEF X}...{$ELSE}{$ENDIF}) left an orphan{inCleanedSrc, soExplorereported "unexpected end of source" on valid code —https://gitlab.com/freepascal.org/lazarus/lazarus/-/merge_requests/775