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/gopls/internal/lsp/fake: file edits in regression tests cause diffs with invalid edits #57627

Closed
findleyr opened this issue Jan 5, 2023 · 3 comments
Assignees
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@findleyr
Copy link
Contributor

findleyr commented Jan 5, 2023

Just encountered in a regtest: formatting a particular go.work file (that isn't newline terminated) results in out of bounds edits:

env.OpenFile("go.work")
env.SetBufferContent("go.work", "go 1.18\nuse moda/a")
env.Save("go.work")
        metadata_test.go:175: formatting before save: editing "go.work": diff has out-of-bounds edits; edits:
            [{1:0 1:0
            } {2:0 2:0
            }]

CC @adonovan @pjweinb

@findleyr findleyr added this to the gopls/v0.12.0 milestone Jan 5, 2023
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Jan 5, 2023
@adonovan adonovan self-assigned this Jan 5, 2023
@adonovan
Copy link
Member

adonovan commented Jan 5, 2023

Minimal repro:

	const before = "go 1.18\nuse moda/a"
	const after = "go 1.18\n\nuse moda/a\n"
	if _, err := diff.Apply(before, diff.Strings(before, after)); err != nil {
		log.Fatal(err)
	}

[UPDATE: I am mistaken. Correct analysis pending.]

@adonovan adonovan changed the title x/tools/gopls: out of bounds edits for work file x/tools/internal/diff: diff generates invalid edits Jan 5, 2023
@adonovan adonovan assigned pjweinb and unassigned pjweinb Jan 5, 2023
@gopherbot
Copy link

Change https://go.dev/cl/460856 mentions this issue: gopls/internal/lsp/fake: fix EOF bug in applyEdits

@adonovan
Copy link
Member

adonovan commented Jan 5, 2023

The bug is in the fake editor's applyEdits function. Fix pending. (Sorry for casting aspersions on the diff package, which hasn't had any bugs yet.)

@adonovan adonovan changed the title x/tools/internal/diff: diff generates invalid edits x/tools/gopls/internal/lsp/fake: file edits in regression tests cause diffs with invalid edits Jan 5, 2023
@golang golang locked and limited conversation to collaborators Jan 6, 2024
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. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants