Skip to content

Pubspec doesn't populate the available versions anymore #3731

Closed

Description

@HerrNiklasRaab

Activity

  1. DanTup commented on Dec 14, 2021

    @DanTup
    Member

    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.

  2. DanTup commented on Dec 14, 2021

    @DanTup
    Member

    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

  3. added this to the v3.32.0 milestone on Dec 14, 2021
  4. added
    in editorRelates to code editing or language features
    in lsp/analysis serverSomething to be fixed in the Dart analysis server
    on Dec 14, 2021
  5. DanTup commented on Dec 14, 2021

    @DanTup
    Member

    @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

  6. bwilkerson commented on Dec 14, 2021

    @bwilkerson

    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?

  7. DanTup commented on Dec 14, 2021

    @DanTup
    Member

    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.

  8. DanTup commented on Dec 29, 2021

    @DanTup
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in editorRelates to code editing or language featuresin lsp/analysis serverSomething to be fixed in the Dart analysis serveris bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions