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

Pubspec doesn't populate the available versions anymore #3731

Closed
HerrNiklasRaab opened this issue Dec 14, 2021 · 6 comments
Closed

Pubspec doesn't populate the available versions anymore #3731

HerrNiklasRaab opened this issue Dec 14, 2021 · 6 comments
Labels
in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server is bug
Milestone

Comments

@HerrNiklasRaab
Copy link

Dart-Code-Log-2021-11-02 11-59-22.txt

Ohne.Titel.mov
@DanTup
Copy link
Member

DanTup commented Dec 14, 2021

Hmm, this is odd. In the attached log the completion is there:

Request

{
	"jsonrpc": "2.0",
	"id": 9671,
	"method": "textDocument/completion",
	"params": {
		"textDocument": {
			"uri": "file:///Users/niklasraab/Github/brokkoli/brokkoli_app/pubspec.yaml"
		},
		"position": {
			"line": 50,
			"character": 10
		},
		"context": {
			"triggerKind": 1
		}
	}
}

Response

{
	"id": 9671,
	"jsonrpc": "2.0",
	"result": [
		{
			"label": "^0.27.3",
			"kind": 6,
			"detail": "latest",
			"sortText": "9998999",
			"textEdit": {
				"range": {
					"start": {
						"line": 51,
						"character": 7
					},
					"end": {
						"line": 51,
						"character": 7
					}
				},
				"newText": "^0.27.3"
			}
		}
	]
}

I can reproduce the same though - it shows up in the logs, but VS Code says there are no results. This could be a VS Code issue - I'll try to make a small repro and raise it there if it appears so.

@DanTup
Copy link
Member

DanTup commented Dec 14, 2021

Nope, this is totally on me. In the case where there's a space at the end of the line, the completion item returned has a range starting from the next line, which I guess is causing VS Code to filter it out.

Screenshot 2021-12-14 at 14 41 14

@DanTup DanTup added this to the v3.32.0 milestone Dec 14, 2021
@DanTup DanTup added in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server labels Dec 14, 2021
@DanTup
Copy link
Member

DanTup commented Dec 14, 2021

@bwilkerson I'm having trouble reproducing this in a test (although I can reproduce it reliably through VS Code) and wonder if you have any ideas that might help understand why. Here's the behaviour I'm seeing:

  • open pubspec.yaml
  • send completion at the end of a line that contains a dependency " foo:" (with no trailing whitespace)
  • server returns expected results (the version numbers for package foo)
  • cancel the completion (don't accept any value)
  • modify the pubspec to add trailing space after the colon: " foo: "
  • send completion at the new offset (after the space)
  • server returns the correct completion results, but the line/col for the edit are wrong (which causes VS Code to filter them out because they're not on the correct line)

The reason the offsets of the edits are wrong seems to be that the LineInfo we get seems to be stale. The lineStarts for it are the same for both completion requests even though the file had a character inserted in the middle between those requests. Unfortunately I can't reproduce this in a test (nor can I currently attach a debugger to VS Code to debug the live instance due to another bug) so it's difficult to step through.

The LineInfo is fetched through this code here and I'm now wondering whether I should be asking a "Dart analysis driver" for non-Dart files to get their LineInfos? Perhaps that's the issue and they're not being invalidated? Although that wouldn't explain why it seems ok in the tests. If that's not correct, what's the correct way to get a LineInfo for a YAML file? (should it just be built from the content in the resourceProvider)?

https://github.com/dart-lang/sdk/blob/979f3ea79ee188ec2e0c039a3186ebd28e0f636c/pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart#L264-L270

@bwilkerson
Copy link

I'm now wondering whether I should be asking a "Dart analysis driver" for non-Dart files to get their LineInfos? Perhaps that's the issue and they're not being invalidated?

That seems quite likely to be the case.

(should it just be built from the content in the resourceProvider)?

Yes. I'd try making that change to see whether that fixes the problem.

Is this only a problem for LSP, or does this also happen in the legacy protocol?

@DanTup
Copy link
Member

DanTup commented Dec 14, 2021

Is this only a problem for LSP, or does this also happen in the legacy protocol?

Just LSP, but we don't need to translate positions using LineInfos for the legacy protocol (we translate them on the VS Code side in the client).

Yes. I'd try making that change to see whether that fixes the problem.

Seems like it does! :) I'm not sure why I couldn't repro in tests, I guess something must have been different. Sounds like the old code is bad anyway, so I'll just fix this. Seems like this could have affected any non-Dart file, so not just YAML here but also files being handled by plugins.

@DanTup
Copy link
Member

DanTup commented Dec 29, 2021

Fixed by dart-lang/sdk@295aea1.

@DanTup DanTup closed this as completed Dec 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server is bug
Projects
None yet
Development

No branches or pull requests

3 participants