Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lsp: Update contents before diagnosticRequestFile #1100

Merged
merged 1 commit into from
Sep 11, 2024

Conversation

charlieegan3
Copy link
Member

One of the main causes for the 'empty module' error stemmed from the sending of diagnosticRequestFile events with no content.

One solution would have been to fetch the content when processing events on the diagnosticRequestFile channel, however it felt like the publisher had more knowledge of how to do this correctly and processing diagnosticRequestFile was getting unwieldy.

I have removed the content from diagnosticRequestFile, and these events will just update the parse and send diagnostics. This should be less surprising.

@@ -115,9 +115,8 @@ type LanguageServer struct {

// fileUpdateEvent is sent to a channel when an update is required for a file.
type fileUpdateEvent struct {
Reason string
URI string
Content string
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been removed so it's no longer possible to send fileUpdateEvents with no content, this reduces the responsibility on the diagnostics worker. Now it can just update parses and send diagnostics.

@@ -212,9 +211,11 @@ func (l *LanguageServer) StartDiagnosticsWorker(ctx context.Context) {
case <-ctx.Done():
return
case evt := <-l.diagnosticRequestFile:
err := l.processTextContentUpdate(ctx, evt.URI, evt.Content)
// updateParse will not return an error when the parsing failed,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

processTextContentUpdate has been removed and inlined here.

@@ -260,9 +265,42 @@ func (l *LanguageServer) StartHoverWorker(ctx context.Context) {
case <-ctx.Done():
return
case evt := <-l.builtinsPositionFile:
err := l.processHoverContentUpdate(ctx, evt.URI, evt.Content)
fileURI := evt.URI
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

processHoverContentUpdate has also been inlined here.

Copy link
Member

@anderseknert anderseknert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd lie if I said I understood this fully, but I think I followed along pretty well :)

Reason: "internal/templateNewFile",
URI: fileURI,
Content: newContents,
Reason: "internal/templateNewFile",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual issue this fixes was triggered by

https://github.com/StyraInc/regal/pull/1100/files#diff-0077cc8440363b2137f8e3e405549e59083242b4281d50b08702a6b7153492a8R751-R756

Where an empty update was sent causing the cache's state to be set to blank for files when they were detected as new, despite them first having their contents loaded from disk.

One of the main causes for the 'empty module' error stemmed from the
sending of diagnosticRequestFile events with no content.

One solution would have been to fetch the content when processing
events on the diagnosticRequestFile channel, however it felt like the
publisher had more knowledge of how to do this correctly and
processing diagnosticRequestFile was getting unwieldy.

I have removed the content from diagnosticRequestFile, and these events
will just update the parse and send diagnostics. This should be less
surprising.

Signed-off-by: Charlie Egan <charlie@styra.com>
@charlieegan3 charlieegan3 merged commit b4e5a8e into StyraInc:main Sep 11, 2024
4 checks passed
srenatus pushed a commit to srenatus/regal that referenced this pull request Oct 1, 2024
One of the main causes for the 'empty module' error stemmed from the
sending of diagnosticRequestFile events with no content.

One solution would have been to fetch the content when processing
events on the diagnosticRequestFile channel, however it felt like the
publisher had more knowledge of how to do this correctly and
processing diagnosticRequestFile was getting unwieldy.

I have removed the content from diagnosticRequestFile, and these events
will just update the parse and send diagnostics. This should be less
surprising.

Signed-off-by: Charlie Egan <charlie@styra.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants