Commit Graph

40 Commits

Author SHA1 Message Date
Rintaro Ishizaki 26f8efed5f [TestDiscovery] Use file modification time to filter semantic index
Instead of querying the index twice (once for up-to-date files, once for
outdated ones), collect file modification timestamps during the syntactic
scan phase and use them to filter a single semantic index query.
For files that don't support syntactic scans, use the semantic index
results even if outdated.

Also extracts symlink-aware mtime resolution into URL.fileModificationDate
and exposes snapshotHasInMemoryModifications(_:) on DocumentManager.
2026-03-06 15:33:19 -08:00
Divya Prakash 0ca0660d99 Refactor DocumentManager threading for Swift 6
Replaces DispatchQueue with ThreadSafeBox, relaxes T: Sendable constraints, and removes @unchecked Sendable from Document.
2025-12-21 19:26:02 +05:30
Divya Prakash d9072850e0 Mark Document as @unchecked Sendable to allow storage in ThreadSafeBox 2025-12-20 09:55:20 +05:30
Divya Prakash 447393e085 Refactor DocumentManager to use ThreadSafeBox for document storage 2025-12-20 09:49:54 +05:30
Owen Voorhees f04b971726 Adopt swift-tools-protocols 2025-10-31 14:11:11 -07:00
Alex Hoppen 1cfa8db1d8 Require Swift 6 to build SourceKit-LSP
This significantly cleans up our `import` statements
2025-03-07 08:05:49 -08:00
Alex Hoppen 1f33ed484d Split SKUtilities from SKSupport 2024-11-13 16:53:54 -08:00
Alex Hoppen 1d7c27bc4b Adopt MemberImportVisibility 2024-11-05 21:04:01 -08:00
Alex Hoppen 2a84422d00 Make DocumentManager.documents private
`documents` needs to be guarded by `queue` and thus shouldn’t be accessible from outside the type. Also uncovered on incorrect use of it.
2024-10-16 11:23:57 -07:00
Alex Hoppen 8cd831b55d Adopt InternalImportsByDefault 2024-09-27 09:17:13 -07:00
Alex Hoppen 0bb605d641 Remove a few workarounds that should no longer be needed 2024-08-07 10:00:04 -07:00
Alex Hoppen 50a28bb86a Change FIXME and TODO comments to always have an associated issue
Do one of the following for every `FIXME` or `TODO` comment
- Add an issue that tracks the task
- Remove the comment if we are not planning to address it
2024-08-07 10:00:04 -07:00
Alex Hoppen 8c34a76f59 Rename LSPLogging to SKLogging 2024-07-25 09:11:13 -07:00
Alex Hoppen 2877675bd5 Adopt package access level
Change a l public declarations to the `package` access level, accept for:
- The `LanguageServerProtocol` module
- The `BuildServerProtocol` module
- `InProcessClient.InProcessSourceKitLSPClient`
- `LanguageServerProtocolJSONRPC` (I would like to create a more ergonomic API for this like `InProcessSourceKitLSPClient` in the future, but for now, we’ll leave it public)

Unfortunately, our pattern of marking functions as `@_spi(Testing) public` no longer works with the `package` access level because declarations at the `package` access level cannot be marked as SPI. I have decided to just mark these functions as `package`. Alternatives would be:
- Add an underscore to these functions, like we did for functions exposed for testing before the introduction of `SPI`
- Use `@testable` import in the test targets and mark the methods as `internal`

Resolves #1315
rdar://128295618
2024-07-19 09:54:30 -07:00
Louis Qian 3be034233b fix: SwiftLanguageService instead of ClangLanguageService
fix!: remove `documentManager` property

fix!: remove `documentManager` in constructor

fix: added documentManager as a computed Property

fix: remove old documentmanager resetting step

fix!: get throws instead of crashing server

fix: throw ResponseError instead of NSError

fix: adding try & orLog where necesary

fix: refined orLog usage

style: ran swift-format

fix: document being opened twice

fix(DocumentManager): remove unwanted comments

lint: ran swift format
2024-07-03 23:48:49 -05:00
Alex Hoppen 80c214b008 Change CheckedIndex to use DocumentURI instead of URL 2024-06-01 12:54:07 -07:00
Lokesh.T.R 087ea64ed3 Rename note to notification throughout the codebase wherever necessary 2024-05-29 17:58:04 +00:00
Alex Hoppen 7e7df04b48 Make the SourceKitLSP module build in Swift 6 mode
Swift 6 mode didn’t find any notable data races. But it’s good to know Swift 6 will prevent future ones.
2024-05-13 21:28:42 -07:00
Alex Hoppen 1f87e7fc4b Move CheckedIndex to a new SemanticIndex module 2024-05-03 14:48:15 -07:00
Alex Hoppen 08f1595b5b Never return nil for position conversions
Instead of returning `nil` to indicate that the position conversion failed, log a fault and perform a best-effort recovery.

I think this allows us to perform better recovery and also makes code calling these position conversions a lot simpler because it doesn’t need to make decisions about what to do if position conversions fail.
2024-04-11 13:59:17 -07:00
Alex Hoppen 0de726d280 Merge pull request #1161 from ahoppen/unify-position-conversion-error-logging
Unify logging of errors during position conversions
2024-04-05 14:02:26 -07:00
Alex Hoppen d62c4ce9fa Unify logging of errors during position conversions
Instead of logging errors in position translation ad-hoc at the caller’s side (and ofter forgetting to do so), log these errors in `LineTable`. To be able to debug where the position conversion error is coming from, also log the file name and line number of the caller.

rdar://125545620
2024-04-05 06:56:59 -07:00
Alex Hoppen cb14bd0948 Don’t fatalError if TextDocumentContentChangeEvent could not be converted to a SourceEdit 2024-04-04 11:05:53 -07:00
mustiikhalil f7f2cea7c5 Refactor willEditDocument in favor of SourceEdits
Removes willEditDocument completion block in favor of a returning SourceEdits instead.
2024-03-05 07:00:58 +01:00
Alex Hoppen 96e0e48b0d Make DocumentManager.latestSnapshot throw if no snapshot exists for the URI
This simplifies most calls that would log an error + return an empty response if no document was found.
2023-10-27 12:59:44 -07:00
Alex Hoppen f960d7ed9b Change logging to use OSLog
OSLog is the suggesting logging solution on Apple platforms and we should be using it there, taking advantage of the different log levels and privacy masking.

Switch sourcekit-lsp to use OSLog on Apple platforms and implement a logger that is API-compatible with OSLog for all uses in sourcekit-lsp and which can be used on non-Darwin platforms.

The goal of this commit is to introduce the new logging API. There are still improvements about what we log and we can display more privacy-insensitive information after masking. Those changes will be in follow-up commits.
2023-10-13 13:46:32 -07:00
Alex Hoppen d0fc00ce98 Format using swift-format
Add `.swift-format` to the repo and format the repo with `swift-format`.

This commit does not add any automation to enforce formatting of sourcekit-lsp in CI. The goal of this commit is to get the majority of source changes out of the way so that the diff of actually enforcing formatting will have fewer changes or conflicts.
2023-10-10 13:44:47 -07:00
Alex Hoppen 2d44263165 Keep track of semantic tokens in a SemanticTokensManager
Storing the semantic tokens inside `Document` was an anti-pattern because the semantic tokens only applied to Swift and were also being updated while the document contents themselves stayed constant.

Instead, we should store the semantic tokens in a separate `SemanticTokensManager` that only exists in the `SwiftLanguageServer` and has the sole responsibility of tracking semantic tokens.
2023-10-06 14:25:29 -07:00
Alex Hoppen 88cd743b79 Introduce SyntaxTreeManager that keeps track of the SwiftSyntax trees for documents
This allows us to use Swift concurrency to await the computation of the SwiftSyntax tree for a given document instead of having to poll for its creation.
2023-10-06 14:25:06 -07:00
Alex Hoppen 7ab3b048be Introduce an ID for DocumentSnapshot 2023-10-06 07:28:53 -07:00
Alex Hoppen 556a58a05e Make DocumentSnapshot not have a reference to its originating Document
The reference just isn’t needed and this makes everything clearer.
2023-10-06 07:26:27 -07:00
Alex Hoppen 818be5eb86 Make members of DocumentSnapshot immutable 2023-10-06 07:17:26 -07:00
Max Desiatov f5a30d9351 Fix uses of deprecated non-throwing AbsolutePath.init (#709)
These warnings appeared after an update to TSC deprecated this initializer.
2023-02-09 14:04:57 +00:00
Robert Widmann fdae671359 Refactor DocumentTokens to Use the New Parser
Re-core the "lexical" token stream on top of SwiftSyntax and call into the parser to (re-)generate these "lexical tokens" when the document changes. Leave the semantic tokens alone since they take some non-zero amount of name lookup to fully resolve references to fully replicate.
2022-10-18 00:47:20 -07:00
Alex Hoppen a4118a57bb Make SourceKitServer own the DocumentManager
When we introduce multiple workspaces, they need to share the same DocumentManager so we don’t accidentally open a Swift file twice in two workspaces that share the same `SwiftLanguageService`. Thus, `SourceKitServer` needs to start owning the document manager.
2022-05-04 14:48:31 +02:00
Ben Langmuir 3927e639be Revert "Support opening multiple workspaces in a single sourcekit-lsp instance" 2022-05-03 13:47:19 -07:00
Alex Hoppen ab946dbdca Make SourceKitServer own the DocumentManager
When we introduce multiple workspaces, they need to share the same DocumentManager so we don’t accidentally open a Swift file twice in two workspaces that share the same `SwiftLanguageService`. Thus, `SourceKitServer` needs to start owning the document manager.
2022-04-29 14:33:01 +02:00
Alex Hoppen fb97fc7350 Extract range adjustments after edit into standalone type
This allows us to re-use the adjuster to adjust ranges of diagnostics as well later on.
2022-01-24 19:34:59 +01:00
Fredrik Wieczerkowski 17f656865d Implement lexical and semantic highlighting for Swift
This is an implementation of LSP's semantic tokens for Swift. Both
lexical and semantic tokens are provided by using the syntaxmap and the
semantic annotations provided as part of SourceKit's open responses and
document update notifications.

While lexical tokens are parsed and stored in the DocumentManager
synchronously, semantic tokens are provided asynchronously. If an edit
occurs, tokens are automatically shifted by the DocumentManager. This is
especially relevant for lexical tokens, which are updated in deltas.

In addition, unit tests are added that assert that both lexical and
semantic tokens are provided and shifted correctly upon edits.
2021-08-24 16:49:52 +02:00
Ben Langmuir 4ff14d278d Rename module SourceKit -> SourceKitLSP
Clarify its role, since it is not really an LSP-independent interface
right now.
2020-06-04 14:49:00 -07:00