Skip to content

[Windows] SourceKit-LSP does not provide IntelliSense for types outside of current file #479

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

Closed
broken-bytes opened this issue Jan 21, 2023 · 51 comments
Labels
bug Something isn't working sourcekit-lsp SourceKit-LSP issue waiting on input Stalled waiting on Input windows Issue specific to Windows

Comments

@broken-bytes
Copy link

broken-bytes commented Jan 21, 2023

Describe the bug
IntelliSense does not seem to pick up types that are not in the same file. I do not get any auto-completion, nor proper error highlighting if the type I want to access is not part of the current file.

Update: Go to References etc. does not work either.

Building works just fine, so the issue must be with SourceKit-LSP.

To Reproduce

  1. Create a new Swift Package Project
  2. Open it in VSCode
  3. Create Type A in File 1 and Type B in File 2
  4. Try using anything from type B inside file A
  5. The editor will not show any IntelliSense or errors.

Expected behavior
The editor should automatically provide these features no matter in what file other types are.

Environment

  • OS: Windows 11
  • Swift: 5.7.2-Release
  • Visual Studio Code version: 1.74.3
  • vscode-swift version: v.1.0.

Additional context
Tried with Swift 5.6, 5.7.1, and 5.7.2

@broken-bytes broken-bytes added the bug Something isn't working label Jan 21, 2023
@PoetaKodu
Copy link

Same here, I just installed latest Swift for Windows and the extension.

@broken-bytes
Copy link
Author

I might be mistaken but I think that it did work a few versions back. Can not say for sure

@GideonUng
Copy link

no this has never worked. i have reported this before and the issue was just closed after a while.
5.7.3 also not working on windows.

@broken-bytes
Copy link
Author

Hope they will look into it if this issue gets more traction

@adam-fowler
Copy link
Contributor

adam-fowler commented Jan 22, 2023

Source editing feature like jump to definition, symbol completion only work after you have built your project.

There is also a bug with SourceKit-LSP. To get it to recognise the project has been rebuilt (the first time) you need to restart the LSP server. I have added an issue to the SourceKit-LSP repo swiftlang/sourcekit-lsp#620 for this.

While this is still an issue I also added a Restart LSP Server command as a quick way to restart the server.

@broken-bytes
Copy link
Author

Source editing feature like jump to definition, symbol completion only work after you have built your project.

There is also a bug with SourceKit-LSP. To get it to recognise the project has been rebuilt (the first time) you need to restart the LSP server. I have added an issue to the SourceKit-LSP repo swiftlang/sourcekit-lsp#620 for this.

While this is still an issue I also added a Restart LSP Server command as a quick way to restart the server.

I am aware of this. But this does not apply to windows. Rebuilding does not change anything. I did rebuild via the task, and terminal, issue persists.

Restarting the LSP server does not help either. The feature just doesn't work on windows at all

@adam-fowler adam-fowler added the sourcekit-lsp SourceKit-LSP issue label Jan 22, 2023
@adam-fowler
Copy link
Contributor

The feature just doesn't work on windows at all

I've just seen it work on Windows. I double checked before posting my response.

In the settings can you set the SourceKit-LSP tracing to verbose, restart vscode (or run Developer: Reload Window), attempt a go to references and then post the contents of the SourceKit Language Server output window here

@broken-bytes
Copy link
Author

The feature just doesn't work on windows at all

I've just seen it work on Windows. I double checked before posting my response.

In the settings can you set the SourceKit-LSP tracing to verbose, restart vscode (or run Developer: Reload Window), attempt a go to references and then post the contents of the SourceKit Language Server output window here

Hmm that is weird. Restarting didn't help for me. I'll do what you said in a minute.

Are you using the same toolchain ?

@adam-fowler
Copy link
Contributor

I'm using
vscode-swift 1.0.0
swift: 5.7.2
Windows 11 (running through parallels)
No need to hurry I'm probably going to be away from the computer for a wee while

@broken-bytes
Copy link
Author

broken-bytes commented Jan 22, 2023

@adam-fowler Still no luck.
See my log:

[Trace - 20:26:07] Sending request 'initialize - (0)'.
Params: {
    "processId": 33348,
    "clientInfo": {
        "name": "Visual Studio Code",
        "version": "1.74.3"
    },
    "locale": "en-us",
    "rootPath": "h:\\Projects\\Kyanite\\Kyanite\\Scripting",
    "rootUri": "file:///h%3A/Projects/Kyanite/Kyanite/Scripting",
    "capabilities": {
        "workspace": {
            "applyEdit": true,
            "workspaceEdit": {
                "documentChanges": true,
                "resourceOperations": [
                    "create",
                    "rename",
                    "delete"
                ],
                "failureHandling": "textOnlyTransactional",
                "normalizesLineEndings": true,
                "changeAnnotationSupport": {
                    "groupsOnLabel": true
                }
            },
            "configuration": true,
            "didChangeWatchedFiles": {
                "dynamicRegistration": true,
                "relativePatternSupport": true
            },
            "symbol": {
                "dynamicRegistration": true,
                "symbolKind": {
                    "valueSet": [
                        1,
                        2,
                        3,
                        4,
                        5,
                        6,
                        7,
                        8,
                        9,
                        10,
                        11,
                        12,
                        13,
                        14,
                        15,
                        16,
                        17,
                        18,
                        19,
                        20,
                        21,
                        22,
                        23,
                        24,
                        25,
                        26
                    ]
                },
                "tagSupport": {
                    "valueSet": [
                        1
                    ]
                },
                "resolveSupport": {
                    "properties": [
                        "location.range"
                    ]
                }
            },
            "codeLens": {
                "refreshSupport": true
            },
            "executeCommand": {
                "dynamicRegistration": true
            },
            "didChangeConfiguration": {
                "dynamicRegistration": true
            },
            "workspaceFolders": true,
            "semanticTokens": {
                "refreshSupport": true
            },
            "fileOperations": {
                "dynamicRegistration": true,
                "didCreate": true,
                "didRename": true,
                "didDelete": true,
                "willCreate": true,
                "willRename": true,
                "willDelete": true
            },
            "inlineValue": {
                "refreshSupport": true
            },
            "inlayHint": {
                "refreshSupport": true
            },
            "diagnostics": {
                "refreshSupport": true
            }
        },
        "textDocument": {
            "publishDiagnostics": {
                "relatedInformation": true,
                "versionSupport": false,
                "tagSupport": {
                    "valueSet": [
                        1,
                        2
                    ]
                },
                "codeDescriptionSupport": true,
                "dataSupport": true
            },
            "synchronization": {
                "dynamicRegistration": true,
                "willSave": true,
                "willSaveWaitUntil": true,
                "didSave": true
            },
            "completion": {
                "dynamicRegistration": true,
                "contextSupport": true,
                "completionItem": {
                    "snippetSupport": true,
                    "commitCharactersSupport": true,
                    "documentationFormat": [
                        "markdown",
                        "plaintext"
                    ],
                    "deprecatedSupport": true,
                    "preselectSupport": true,
                    "tagSupport": {
                        "valueSet": [
                            1
                        ]
                    },
                    "insertReplaceSupport": true,
                    "resolveSupport": {
                        "properties": [
                            "documentation",
                            "detail",
                            "additionalTextEdits"
                        ]
                    },
                    "insertTextModeSupport": {
                        "valueSet": [
                            1,
                            2
                        ]
                    },
                    "labelDetailsSupport": true
                },
                "insertTextMode": 2,
                "completionItemKind": {
                    "valueSet": [
                        1,
                        2,
                        3,
                        4,
                        5,
                        6,
                        7,
                        8,
                        9,
                        10,
                        11,
                        12,
                        13,
                        14,
                        15,
                        16,
                        17,
                        18,
                        19,
                        20,
                        21,
                        22,
                        23,
                        24,
                        25
                    ]
                },
                "completionList": {
                    "itemDefaults": [
                        "commitCharacters",
                        "editRange",
                        "insertTextFormat",
                        "insertTextMode"
                    ]
                }
            },
            "hover": {
                "dynamicRegistration": true,
                "contentFormat": [
                    "markdown",
                    "plaintext"
                ]
            },
            "signatureHelp": {
                "dynamicRegistration": true,
                "signatureInformation": {
                    "documentationFormat": [
                        "markdown",
                        "plaintext"
                    ],
                    "parameterInformation": {
                        "labelOffsetSupport": true
                    },
                    "activeParameterSupport": true
                },
                "contextSupport": true
            },
            "definition": {
                "dynamicRegistration": true,
                "linkSupport": true
            },
            "references": {
                "dynamicRegistration": true
            },
            "documentHighlight": {
                "dynamicRegistration": true
            },
            "documentSymbol": {
                "dynamicRegistration": true,
                "symbolKind": {
                    "valueSet": [
                        1,
                        2,
                        3,
                        4,
                        5,
                        6,
                        7,
                        8,
                        9,
                        10,
                        11,
                        12,
                        13,
                        14,
                        15,
                        16,
                        17,
                        18,
                        19,
                        20,
                        21,
                        22,
                        23,
                        24,
                        25,
                        26
                    ]
                },
                "hierarchicalDocumentSymbolSupport": true,
                "tagSupport": {
                    "valueSet": [
                        1
                    ]
                },
                "labelSupport": true
            },
            "codeAction": {
                "dynamicRegistration": true,
                "isPreferredSupport": true,
                "disabledSupport": true,
                "dataSupport": true,
                "resolveSupport": {
                    "properties": [
                        "edit"
                    ]
                },
                "codeActionLiteralSupport": {
                    "codeActionKind": {
                        "valueSet": [
                            "",
                            "quickfix",
                            "refactor",
                            "refactor.extract",
                            "refactor.inline",
                            "refactor.rewrite",
                            "source",
                            "source.organizeImports"
                        ]
                    }
                },
                "honorsChangeAnnotations": false
            },
            "codeLens": {
                "dynamicRegistration": true
            },
            "formatting": {
                "dynamicRegistration": true
            },
            "rangeFormatting": {
                "dynamicRegistration": true
            },
            "onTypeFormatting": {
                "dynamicRegistration": true
            },
            "rename": {
                "dynamicRegistration": true,
                "prepareSupport": true,
                "prepareSupportDefaultBehavior": 1,
                "honorsChangeAnnotations": true
            },
            "documentLink": {
                "dynamicRegistration": true,
                "tooltipSupport": true
            },
            "typeDefinition": {
                "dynamicRegistration": true,
                "linkSupport": true
            },
            "implementation": {
                "dynamicRegistration": true,
                "linkSupport": true
            },
            "colorProvider": {
                "dynamicRegistration": true
            },
            "foldingRange": {
                "dynamicRegistration": true,
                "rangeLimit": 5000,
                "lineFoldingOnly": true,
                "foldingRangeKind": {
                    "valueSet": [
                        "comment",
                        "imports",
                        "region"
                    ]
                },
                "foldingRange": {
                    "collapsedText": false
                }
            },
            "declaration": {
                "dynamicRegistration": true,
                "linkSupport": true
            },
            "selectionRange": {
                "dynamicRegistration": true
            },
            "callHierarchy": {
                "dynamicRegistration": true
            },
            "semanticTokens": {
                "dynamicRegistration": true,
                "tokenTypes": [
                    "namespace",
                    "type",
                    "class",
                    "enum",
                    "interface",
                    "struct",
                    "typeParameter",
                    "parameter",
                    "variable",
                    "property",
                    "enumMember",
                    "event",
                    "function",
                    "method",
                    "macro",
                    "keyword",
                    "modifier",
                    "comment",
                    "string",
                    "number",
                    "regexp",
                    "operator",
                    "decorator"
                ],
                "tokenModifiers": [
                    "declaration",
                    "definition",
                    "readonly",
                    "static",
                    "deprecated",
                    "abstract",
                    "async",
                    "modification",
                    "documentation",
                    "defaultLibrary"
                ],
                "formats": [
                    "relative"
                ],
                "requests": {
                    "range": true,
                    "full": {
                        "delta": true
                    }
                },
                "multilineTokenSupport": false,
                "overlappingTokenSupport": false,
                "serverCancelSupport": true,
                "augmentsSyntaxTokens": true
            },
            "linkedEditingRange": {
                "dynamicRegistration": true
            },
            "typeHierarchy": {
                "dynamicRegistration": true
            },
            "inlineValue": {
                "dynamicRegistration": true
            },
            "inlayHint": {
                "dynamicRegistration": true,
                "resolveSupport": {
                    "properties": [
                        "tooltip",
                        "textEdits",
                        "label.tooltip",
                        "label.location",
                        "label.command"
                    ]
                }
            },
            "diagnostic": {
                "dynamicRegistration": true,
                "relatedDocumentSupport": false
            }
        },
        "window": {
            "showMessage": {
                "messageActionItem": {
                    "additionalPropertiesSupport": true
                }
            },
            "showDocument": {
                "support": true
            },
            "workDoneProgress": true
        },
        "general": {
            "staleRequestSupport": {
                "cancel": true,
                "retryOnContentModified": [
                    "textDocument/semanticTokens/full",
                    "textDocument/semanticTokens/range",
                    "textDocument/semanticTokens/full/delta"
                ]
            },
            "regularExpressions": {
                "engine": "ECMAScript",
                "version": "ES2020"
            },
            "markdown": {
                "parser": "marked",
                "version": "1.1.0"
            },
            "positionEncodings": [
                "utf-16"
            ]
        },
        "notebookDocument": {
            "synchronization": {
                "dynamicRegistration": true,
                "executionSummarySupport": true
            }
        }
    },
    "trace": "verbose",
    "workspaceFolders": [
        {
            "uri": "file:///h%3A/Projects/Kyanite/Kyanite/Scripting",
            "name": "Scripting"
        }
    ]
}

@adam-fowler
Copy link
Contributor

Ok you got no response from the server which means it could have crashed, or we never found it. What happens if you type sourcekit-lsp into a command prompt?
Also what are the results of

where swift

and

where sourcekit-lsp

@broken-bytes
Copy link
Author

C:\Users\Marcel>where swift
C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swift.exe

C:\Users\Marcel>where sourcekit-lsp
C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\sourcekit-lsp.exe

@broken-bytes
Copy link
Author

Typing sourcekit-lsp into the terminal does seem to run LSP. I do not get any output, but the task does not close, so something is happening

@adam-fowler
Copy link
Contributor

Ok I've run out of ideas just now, I'm going to have to talk to few other people to see if they have a better idea what is going on here.

@broken-bytes
Copy link
Author

No problem!

I actually never got it to run, I tried a lot of stuff before.

If you need additional info, just notify me here

@compnerd
Copy link
Member

Do you have a Package.swift for the project? It currently is required for getting that to work.

@broken-bytes
Copy link
Author

Of course.

@compnerd
Copy link
Member

How much system RAM do you have? I wonder if there is a configuration difference in the connection (it may be that the dispatch source is hanging).

@broken-bytes
Copy link
Author

I honestly doubt that.

I am on a really fast computer:

  • i7 12700K @5.3Ghz
  • 64GB DDR4 3600
  • 6TB of SSD storage

@broken-bytes
Copy link
Author

broken-bytes commented Jan 23, 2023

The only non-software issue I could possibly see would be me doing something wrong.

But I am always doing this:

  • Open folder with a Package.swift in it
  • Build the project (either with the task or swift build)
  • Restart VSCode to get LSP to restart

@compnerd
Copy link
Member

I have 16G on the machine that I test the LSP on and that runs fine. This is unlikely to be that the pipe is filled up then.

Interesting, I've normally just opened the project and did a build internally with no restart and that would pick up the completion 🤔 .

I wonder if we should step back and try to do this with a project that we all can replicate to find the divergence. Perhaps something like swift-driver would be a good starting point (SourceKit-LSP would be my first suggestion, but that cannot be built with SPM anymore due to SPM forcing and failing to do static linking).

@broken-bytes
Copy link
Author

I'll have to check again but I think even new projects with just two files had the same result.

@compnerd
Copy link
Member

Hmm, would you mind also trying the 5.8 snapshot? I don't have 5.7 installed anymore, I've been using 5.8.

@broken-bytes
Copy link
Author

I'll download it and post my results

@broken-bytes
Copy link
Author

Code completion doesn't work 100% all the time but it does seem to have improved. Was able to get some auto-completion for other file's types. What didn't work was auto-complete for types imported from another dynamic library.
Making the same module a static library made the completion appear again.

@adam-fowler
Copy link
Contributor

Also, is there a way to make it restart always ?

You can't really have it restart always as this would hide issues which are causing the LSP server to crash. I can up the number of retry attempts.

I do have a PR that will allow you to restart the server from the dialog but it is reliant on a beta version of the vs code language client. Hopefully that'll be released in February.

Were you seeing this dialog before with swift 5.7?

@broken-bytes
Copy link
Author

The language server did crash for me on Windows every now and then. Probably at least twice per hour.
And yes, this was the case even back with Swift 5.5.

Always had that issue

@broken-bytes
Copy link
Author

It does happen quite a lot especially when you are working on generics and that stuff.

@adam-fowler
Copy link
Contributor

In the current situation on Windows, where you aren't getting auto-completion etc are you getting the server crashed messsages all the time, ie is auto-completion not working because the server has crashed?

@broken-bytes
Copy link
Author

No.

I did. get the autocomplete to work on Swift 5.8.

The crash is another issue

@adam-fowler
Copy link
Contributor

Yes there are crashes, Swift 5.7 is notably less stable than Swift 5.6. I haven't looked into 5.8 much yet. If you do get one and can work out what test you typed that caused the crash please add them as issues to the SourceKit-LSP repo.

@compnerd
Copy link
Member

What didn't work was auto-complete for types imported from another dynamic library.

Is this a dynamic C/C++ library or a Swift library? This sounds like it may be an include path issue.

@broken-bytes
Copy link
Author

It was just a Swift library. It does import Swift Win32 though

@compnerd
Copy link
Member

That might be the issue. I don't know if SourceKit-LSP picks up flags from the command line; you need to ensure that the include path is setup properly and processed by the LSP to ensure that it can process the module.

@broken-bytes
Copy link
Author

The module does get detected, I also do get proper code-completion.

Just when building it dynamically, I don't get code-completion when importing the target

@compnerd
Copy link
Member

The module does get detected, I also do get proper code-completion.

Just when building it dynamically, I don't get code-completion when importing the target

How are you importing the dynamically linked library? This is something which currently is not possible with SPM - SPM implicitly statically links (incorrectly) code that is built for dynamic linking. The system library infrastructure is not complete either, that is while it has the nuget provider, the import for that is not setup, so this makes me wonder how it is that you are configuring SPM to import the dynamic library and passing along that information to SourceKit-LSP.

@broken-bytes
Copy link
Author

I just import it as a product as usual

@compnerd
Copy link
Member

compnerd commented Feb 3, 2023

@broken-bytes could you give an example of that?

@broken-bytes
Copy link
Author

@compnerd Sorry, I never saw the message here.

I am working on the project right now, I changed some stuff but the issues remain. I can upload it to a public repo later.

Another thing though:
The Swift Dev Branch (5.9) broke LSP for me. The server crashes immediately whenever I try to open some files in VSCode. 5.8 works just fine

@GideonUng
Copy link

Any update on this issue? this bug renders the plugin essentially unusable on windows.

@adam-fowler
Copy link
Contributor

I haven't had any chance to look at this any further. Personally I'm not seeing the issue. I'm guessing it is related to Swift install but not totally sure what it could be.

@GideonUng
Copy link

could it be that your testing machine is tainted? bc i have never managed to get this plugin to work on any of my windows machines and windows installs.

@adam-fowler
Copy link
Contributor

My testing machine gets updated every 3 months as it is a dev image from MS with a limited license (downloaded from https://developer.microsoft.com/en-us/windows/downloads/virtual-machines/) which I run through Parallels.

Once I have that setup I follow the install instructions on the swift.org site (with one minor change). The python install is

winget install Python.Python.3.10

@adam-fowler
Copy link
Contributor

OK looks like I can reproduce this now. I can see commands being sent to the LSP server and it returning empty responses.

I seem to be able to fix it by cleaning the build, and then compiling. If you don't reload the window or restart the LSP server it seems to work. As soon as you reload the window it stops working. This looks like an indexing issue, most likely something internal in the compiler or sourcekit-lsp. I'll investigate a little further see if I can find anything else that can help, but I doubt I'll be the one that resolves this. In the meantime I'll add a bug to the sourcekit-lsp repo.

The other thing I have found out is Restart LSP Server does not work on Windows. The killing of the sourcekit-lsp process takes too long and it returns a timeout error and never starts a new process. This might be related to me running in a VM, but still this shouldn't happen. I'll add an issue to fix this

@adam-fowler
Copy link
Contributor

I seem to be able to fix it by cleaning the build, and then compiling. If you don't reload the window or restart the LSP server it seems to work. As soon as you reload the window it stops working.

@GideonUng can you verify if this works. I want to be sure we are seeing the same thing

@GideonUng
Copy link

GideonUng commented Mar 21, 2023

@adam-fowler yep i can confirm just that. without
.build dir auto completion works and continues to work
if i restart the lsp with a .build dir auto completion fails

@compnerd compnerd assigned compnerd and unassigned compnerd Mar 24, 2023
@GideonUng
Copy link

5.8 resolved this issue for me now :)

@broken-bytes
Copy link
Author

I'll download 5.8 on Windows and test it later

@adam-fowler
Copy link
Contributor

adam-fowler commented Apr 14, 2023

This is also working for me now. I cannot replicate the issues I was seeing three weeks ago. @broken-bytes if you could verify we can then close this.

@adam-fowler adam-fowler added the waiting on input Stalled waiting on Input label May 24, 2023
@adam-fowler
Copy link
Contributor

Closing as we have had no response. There are still known issue, but they are not vscode-swift issues. It looks like they might be issues with the Windows version of Foundation (used in source kit-lsp). See swiftlang/sourcekit-lsp#752

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sourcekit-lsp SourceKit-LSP issue waiting on input Stalled waiting on Input windows Issue specific to Windows
Projects
None yet
Development

No branches or pull requests

5 participants