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

Showing completions after trigger chars can be unstable #71

Open
DoctorKrolic opened this issue Sep 4, 2023 · 8 comments
Open

Showing completions after trigger chars can be unstable #71

DoctorKrolic opened this issue Sep 4, 2023 · 8 comments

Comments

@DoctorKrolic
Copy link
Collaborator

I managed to get a consistent repro of #52 (comment)

Code_d6SArtHd4G
.csproj with this content is the only MSBuild-related file in the project

@tintoy
Copy link
Owner

tintoy commented Sep 4, 2023

Interesting! I'll see if we can create a test for this - we do have a bunch of similar ones and the test infrastructure to be explicit about starting project file and completion location.

@tintoy
Copy link
Owner

tintoy commented Sep 4, 2023

First step will be to verify that we are correctly parsing and interpreting the existing and modified document XML:

https://github.com/tintoy/msbuild-project-tools-server/blob/master/test/LanguageServer.Engine.Tests/XmlLocatorTests.cs (around line 210).

@tintoy
Copy link
Owner

tintoy commented Sep 29, 2023

The initial tests I've added indicate that the language service does correctly recognise all of the target locations for element insertion listed in #129.

I'll keep digging 🙂

@tintoy
Copy link
Owner

tintoy commented Sep 30, 2023

It looks like something has changed in VS Code's LSP implementation; the extension is definitely offering the correct completions but VS Code is not showing them.

Offering completions to replace element "" @ [7,36..7,38)
Completion was triggered by typing one or more characters; target range will be extended by 1 characters toward start of document (now: "[7,35..7,38)").
Offering 747 completion(s) for 7,37 -> [Element, Invalid]:/Project/PropertyGroup/ ([7,36..7,38))

followed by the completions:

[Trace - 5:34:26 PM] Received response 'textDocument/completion - (5)' in 55ms.
Result: [
    {
        "label": "<!-- -->",
        "kind": 1,
        "detail": "Comment",
        "documentation": "XML comment",
        "sortText": "1000<!-- -->",
        "insertTextFormat": 2,
        "textEdit": {
            "range": {
                "start": {
                    "line": 6,
                    "character": 34
                },
                "end": {
                    "line": 6,
                    "character": 37
                }
            },
            "newText": "<!-- $0 -->"
        }
    },
    {
        "label": "<OutputType>",
        "kind": 10,
        "detail": "Property",
        "documentation": "Type of output to generate (WinExe, Exe, or Library)",
        "sortText": "1000<OutputType>",
        "insertTextFormat": 2,
        "textEdit": {
            "range": {
                "start": {
                    "line": 6,
                    "character": 34
                },
                "end": {
                    "line": 6,
                    "character": 37
                }
            },
            "newText": "<OutputType>${1|Library,Exe|}</OutputType>"
        }
    },
    // ... snip ...
    {
        "label": "<RestoreOutputPath>",
        "kind": 10,
        "detail": "Property",
        "documentation": "I don't know anything about the 'RestoreOutputPath' property, but it's defined in this project (or a project that it imports); you can override its value by specifying it here.",
        "sortText": "1010<RestoreOutputPath>",
        "insertTextFormat": 2,
        "textEdit": {
            "range": {
                "start": {
                    "line": 6,
                    "character": 34
                },
                "end": {
                    "line": 6,
                    "character": 37
                }
            },
            "newText": "<RestoreOutputPath>$0</RestoreOutputPath>"
        }
    },
    {
        "label": "<NuspecOutputPath>",
        "kind": 10,
        "detail": "Property",
        "documentation": "I don't know anything about the 'NuspecOutputPath' property, but it's defined in this project (or a project that it imports); you can override its value by specifying it here.",
        "sortText": "1010<NuspecOutputPath>",
        "insertTextFormat": 2,
        "textEdit": {
            "range": {
                "start": {
                    "line": 6,
                    "character": 34
                },
                "end": {
                    "line": 6,
                    "character": 37
                }
            },
            "newText": "<NuspecOutputPath>$0</NuspecOutputPath>"
        }
    }
]

tintoy added a commit that referenced this issue Sep 30, 2023
@tintoy
Copy link
Owner

tintoy commented Oct 8, 2023

Ok, so I have figured out what the problem is:

When you type a trigger character (e.g. <) to trigger completion, we have to tell VS Code to replace some existing text (e.g. <>) if the completion is chosen. The version of LSP our extension supports is so old now that VS Code has dropped support for the old-style newText-with-range completions; they now expect us to use replace instead:

https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#insertReplaceEdit

We can't fix this one without upgrading to a recent version of the OmniSharp LSP library.

@tintoy
Copy link
Owner

tintoy commented Oct 14, 2023

Finally figured out a way to handle this correctly!

I've changed the completion provider behaviour so it no-longer extends the selection when trigger characters are typed to trigger completion (this was previously required because otherwise the completion would not correctly replace them).

tintoy added a commit that referenced this issue Oct 14, 2023
This is no longer needed due to a change in VS Code / LSP completion behaviour.

#71
@tintoy
Copy link
Owner

tintoy commented Oct 14, 2023

@DoctorKrolic can you give this branch a try and see if it works for you?

If so, I'll open a PR for review and publish a new version of the extension.

tintoy added a commit that referenced this issue Oct 14, 2023
This is no longer needed due to a change in VS Code / LSP completion behaviour.

#71
@DoctorKrolic
Copy link
Collaborator Author

Can you please open a PR, so we can discuss the actual code changes there?

tintoy added a commit that referenced this issue Oct 15, 2023
…more trigger characters

This is because VS Code behaviour has changed, and it no longer correctly handles extension of selection if it has inserted an auto-closing delimiter.

#71
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants