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

fix: parse out word for errors and clear them #1163

Merged
merged 1 commit into from
Apr 3, 2024

Conversation

wesbillman
Copy link
Collaborator

Screen.Recording.2024-04-03.at.2.16.13.PM.mov

@alecthomas alecthomas mentioned this pull request Apr 3, 2024
@@ -29,6 +29,10 @@ type schemaChange struct {
*schema.Module
}

type Listener struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be an interface, it's very rare that you would need to use a struct for something like this.

func (s *Server) BuildStarted(dir string) {
dirURI := "file://" + dir

s.diagnostics.Range(func(uri protocol.DocumentUri, diagnostics []protocol.Diagnostic) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Aha!

// getLineOrWordLength returns the length of the line or the length of the word starting at the given column.
// If wholeLine is true, it returns the length of the entire line.
// If wholeLine is false, it returns the length of the word starting at the column.
func getLineOrWordLength(filePath string, lineNum, column int, wholeLine bool) (int, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

While this is probably okay as a stop-gap, we should really be extending the error type to include range information so we can include it when the errors are created, as this is incredibly inefficient.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I started down this path and got pretty hung up on parser stuff (I think that was the source of the issue). It was a bit of a time suck so I just put this in for now to keep moving forward.

I suspect it had something to do with how our schema.Position doesn't exactly match participle.Position but I'm fully just guessing. Once I added EndColumn to schema.Position I lost all position information. I do have a branch with that work though we can pick up when you have a sec :)

Copy link
Collaborator

@alecthomas alecthomas Apr 3, 2024

Choose a reason for hiding this comment

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

Your assumption is correct: the Position type is a mirror of participles so you'll need to either add the end location to the error rather than the position, or include it in our position type and write a function to do the mapping.

@wesbillman wesbillman force-pushed the lsp-error-pos-and-clearing branch from 78d3a56 to 8a58a71 Compare April 3, 2024 22:33
@wesbillman wesbillman merged commit 82ff1bb into main Apr 3, 2024
10 checks passed
@wesbillman wesbillman deleted the lsp-error-pos-and-clearing branch April 3, 2024 22:50
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.

3 participants