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: Correct Path to URI encoding #1083

Merged
merged 1 commit into from
Sep 9, 2024

Conversation

charlieegan3
Copy link
Member

Spaces must be encoded as %20. This case causing the state worker to reload contents from disk as it appeared a file did not exist in the cache.

Spaces must be encoded as %20. This case causing the state worker to
reload contents from disk as it appeared a file did not exist in the cache.

Signed-off-by: Charlie Egan <[email protected]>
@@ -211,18 +211,14 @@ func (l *LanguageServer) StartDiagnosticsWorker(ctx context.Context) {
case <-ctx.Done():
return
case evt := <-l.diagnosticRequestFile:
success, err := l.processTextContentUpdate(ctx, evt.URI, evt.Content)
err := l.processTextContentUpdate(ctx, evt.URI, evt.Content)
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 updated to avoid any special handling of parse errors. diagnostics are always sent from the parent now. This is unrelated to the title fix.

@@ -936,33 +932,24 @@ func (l *LanguageServer) processTextContentUpdate(
ctx context.Context,
Copy link
Member Author

Choose a reason for hiding this comment

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

See note above, this function now just attempts to update the parse if the content changed.

@@ -2132,7 +2119,7 @@ func (l *LanguageServer) loadWorkspaceContents(ctx context.Context, newOnly bool
}

// if the caller has requested only new files, then we can exit early
if _, ok := l.cache.GetModule(fileURI); newOnly && ok {
if _, ok := l.cache.GetFileContents(fileURI); newOnly && ok {
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 best proxy for 'Existence in the cache' is file contents and not a parsed module. This is related to the fix, but is in addition to the required change.

@@ -19,6 +19,9 @@ func FromPath(client clients.Identifier, path string) string {
// Convert Windows path separators to Unix separators
path = filepath.ToSlash(path)

// spaces must be percent-encoded
path = strings.ReplaceAll(path, " ", "%20")
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 is the fix, going from paths to URIs when paths contained spaces was broken. This meant files were being reloaded from disk at incorrect times.

Copy link
Member

Choose a reason for hiding this comment

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

Good find!

@@ -19,6 +19,9 @@ func FromPath(client clients.Identifier, path string) string {
// Convert Windows path separators to Unix separators
path = filepath.ToSlash(path)

// spaces must be percent-encoded
path = strings.ReplaceAll(path, " ", "%20")
Copy link
Member

Choose a reason for hiding this comment

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

Good find!

@charlieegan3 charlieegan3 merged commit 146895c into StyraInc:main Sep 9, 2024
4 checks passed
srenatus pushed a commit to srenatus/regal that referenced this pull request Oct 1, 2024
Spaces must be encoded as %20. This case causing the state worker to
reload contents from disk as it appeared a file did not exist in the cache.

Signed-off-by: Charlie Egan <[email protected]>
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