swiftlang / vscode-swift

Visual Studio Code Extension for Swift
https://marketplace.visualstudio.com/items?itemName=sswg.swift-lang
Apache License 2.0
755 stars 54 forks source link

Errors are not updated properly / editor is displaying old errors. #912

Closed adamwych closed 4 months ago

adamwych commented 4 months ago

Describe the bug VSCode displays (old, cached?) errors if textDocument/hover command does not report any issues.

image

To Reproduce

  1. Create an empty project with Package.swift
  2. Put this into Package.swift:
    
    // swift-tools-version:5.8
    import PackageDescription

let package = Package( name: "Foo", platforms: [ .macOS(.v13) ] )

3. Change `swift-tools-version` to 5.6 and save the file. It will now show an error that `v13` is only available in version 5.7+.
4. Change `swift-tools-version` to 5.9 and save the file.
5. Change tab to another file.
6. Package.swift now shows an error about `v13` not being available in version 5.6 even though 5.9 is specified.

**Expected behavior**
The error should not be reported anymore after it is fixed.

**Environment**
 - OS: macOS 14.3.1
 - Swift version (output of `swift --version`): swiftlang-5.10.0.13 and 6.0-dev (490cf64aee23f13)
 - Visual Studio Code version: 1.90.1
 - vscode-swift version: 1.10.2

**Additional context**
This happens for all kinds of errors, not only when changing `swift-tools-version`.

Initially I thought that it's a bug in sourcekit-lsp, so I also reported it there (https://github.com/apple/sourcekit-lsp/issues/1495), but after enabling extension diagnostics I noticed that the LSP seems to work correctly, it does not return any error for this hover action:

[Trace - 1:43:15 PM] Sending request 'textDocument/hover - (123)'. Params: { "textDocument": { "uri": "<< path to project >>/Package.swift" }, "position": { "line": 7, "character": 6 } }

[Trace - 1:43:15 PM] Received response 'textDocument/hover - (123)' in 23ms. No result returned.

award999 commented 4 months ago

I can reproduce. Sourcekit and swiftc are reporting different diagnostic ranges so the cleanup is not happening. I'll see what we can do. @adamwych thanks for the report, you can run Swift: Clear Diagnostics Collection command to remove this case

award999 commented 4 months ago

Actually realized it was SwiftPM not SourceKit returning the wrong line. Opened https://github.com/apple/swift-package-manager/issues/7688

matthewbastien commented 4 months ago

Verified with db0b840