-
Notifications
You must be signed in to change notification settings - Fork 37
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: Address empty module issues on rename #1078
Conversation
@@ -747,6 +747,8 @@ func (l *LanguageServer) StartTemplateWorker(ctx context.Context) { | |||
newContents, err := l.templateContentsForFile(evt.URI) | |||
if err != nil { | |||
l.logError(fmt.Errorf("failed to template new file: %w", err)) | |||
|
|||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the fix, but when there is an error in templating we should skip the rest.
@@ -790,6 +792,14 @@ func (l *LanguageServer) templateContentsForFile(fileURI string) (string, error) | |||
return "", errors.New("file already has contents, templating not allowed") | |||
} | |||
|
|||
diskContent, err := os.ReadFile(uri.ToPath(l.clientIdentifier, fileURI)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is also not the fix but is an additional guard for templating over files that have contents on disk already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any added safeguards are good 👍
) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to update cache for uri %q: %w", renameOp.NewURI, err) | ||
content, ok := l.cache.GetFileContents(renameOp.OldURI) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the fix for the empty module issue, were we load from the cache first, and only load from disk if it's missing or empty in the cache
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
0f5cacb
to
d241bbf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Test would be good, as with anything touching the LSP, but I know they can be hard to write given the many steps required in sequence. Let's look into how we improve on that later 👍
@@ -790,6 +792,14 @@ func (l *LanguageServer) templateContentsForFile(fileURI string) (string, error) | |||
return "", errors.New("file already has contents, templating not allowed") | |||
} | |||
|
|||
diskContent, err := os.ReadFile(uri.ToPath(l.clientIdentifier, fileURI)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any added safeguards are good 👍
) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to update cache for uri %q: %w", renameOp.NewURI, err) | ||
content, ok := l.cache.GetFileContents(renameOp.OldURI) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
d241bbf
to
126d5a6
Compare
126d5a6
to
c0bef96
Compare
* WIP * Use cache contents before disk
This PR makes changes to where the contents of files come from when being moved. Previously, preference was given to the contents on disk. This turned out to be incorrect as the files on disk are often empty until saved.
I found that I was able to replicate one of the empty module problems by:
before
Screen.Recording.2024-09-09.at.10.32.12.mov
after
Screen.Recording.2024-09-09.at.10.34.16.mov