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

x/tools/internal/lsp/cache: improve method of getting end positions for errors #37936

Closed
ridersofrohan opened this issue Mar 18, 2020 · 1 comment
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. help wanted Tools This label describes issues relating to any tools in the x/tools repository.

Comments

@ridersofrohan
Copy link

When we calculate end positions for errors that originate from go/packages. We do some kind of syntax analysis, but some issues arise when adding new characters to the list in internal/lsp/cache/errors.go#L208

if width := bytes.IndexAny(data[offset:], " \n,():;[]"); width > 0 {
	return ...
}

Take the sample program below:

__ main.go __
package main

import "golang.org/whatever"

func main() {
    if y/2 == 10 { return }
}

We will have two errors: (1) "undeclared name: y" and (2) "could not import golang.org/whatever (no package for import golang.org/whatever)".

In the current state, the diagnostic for error 1 will be on "y+2" and the diagnostic for error 2 will be on "golang.org/whatever".

Now, the diagnostic for error 1 should only underline "y" since that is the undeclared name, to fix this I could add "/" to the character list in internal/lsp/cache/errors.go#L208 but then the diagnostic on error 2 would now underline "golang.org" rather than "golang.org/whatever".

I think gopls needs a better way to compute the end positions for type errors.

@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label Mar 18, 2020
@ridersofrohan ridersofrohan changed the title internal/lsp/cache: getting end positions for type errors x/tools/gopls/internal/lsp/cache: getting end positions for type errors Mar 18, 2020
@ridersofrohan ridersofrohan changed the title x/tools/gopls/internal/lsp/cache: getting end positions for type errors x/tools/internal/lsp/cache: getting end positions for type errors Mar 18, 2020
@gopherbot gopherbot added this to the Unreleased milestone Mar 18, 2020
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Mar 18, 2020
@stamblerre stamblerre modified the milestones: gopls/v1.0.0, gopls/v0.5.0 May 21, 2020
@stamblerre stamblerre removed this from the gopls/v0.5.0 milestone Jun 24, 2020
@golang golang deleted a comment from gopherbot Jun 24, 2020
@stamblerre stamblerre changed the title x/tools/internal/lsp/cache: getting end positions for type errors x/tools/internal/lsp/cache: improve method of getting end positions for errors Jul 23, 2020
@stamblerre stamblerre added this to the gopls/unplanned milestone Oct 21, 2020
@stamblerre
Copy link
Contributor

Superseded by #42290.

@stamblerre stamblerre removed this from the gopls/unplanned milestone Nov 13, 2020
@golang golang locked and limited conversation to collaborators Nov 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. help wanted Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants