Ben Barham b3cb43fb74 Ensure the string passed to PathIsRelativeW is null terminated
`CompilationDatabaseTests` have been flakey on Windows since
https://github.com/swiftlang/sourcekit-lsp/pull/2334. This didn't really
introduce the failure though - it just added tests that now catch it.

The underlying cause is that `filename.isAbsolutePath` sometimes returns
`true` for a relative path, which then causes the CWD to be prepended
instead of the given `compileCommandsDirectory`.

`PathIsRelativeW` requires a null terminated string, so presumably we
were hitting junk after the initial path that sometimes turned it into
an absolute path. From the Windows docs:
> A pointer to a null-terminated string of maximum length MAX_PATH that
contains the path to search.

Fixes #2360
Resolves rdar://165006835
2025-11-20 13:43:49 +10:00
2025-05-14 10:22:44 -07:00
2025-10-31 11:02:54 -04:00
2022-08-03 19:12:43 +02:00
2025-10-31 14:11:11 -07:00
2018-11-13 15:50:48 -08:00

SourceKit-LSP

SourceKit-LSP is an implementation of the Language Server Protocol (LSP) for Swift and C-based languages. It provides intelligent editor functionality like code-completion and jump-to-definition to editors that support LSP. SourceKit-LSP is built on top of sourcekitd and clangd for high-fidelity language support, and provides a powerful source code index as well as cross-language support. SourceKit-LSP supports projects that use the Swift Package Manager and projects that generate a compile_commands.json file, such as CMake.

Getting Started

SourceKit-LSP is included in the the Swift toolchains available on swift.org and is bundled with Xcode.

swift.org/tools has a list of popular editors that support LSP and can thus be hooked up to SourceKit-LSP to provide intelligent editor functionality as well as set-up guides.

Important

SourceKit-LSP does not update its global index in the background or build Swift modules in the background. Thus, a lot of cross-module or global functionality is limited if the project hasn't been built recently. To update the index or rebuild the Swift modules, build your project or enable the experimental background indexing as described in Enable Experimental Background Indexing.

To learn more about SourceKit-LSP, refer to the Documentation.

Note

If you are using SourceKit-LSP with a SwiftPM project in which you need to pass additional arguments to the swift build invocation, as is commonly the case for embedded projects, you need to teach SourceKit-LSP about those arguments as described in Using SourceKit-LSP with Embedded Projects.

Reporting Issues

If you should hit any issues while using SourceKit-LSP, we appreciate bug reports on GitHub Issue.

Contributing

If you want to contribute code to SourceKit-LSP, see CONTRIBUTING.md for more information.

Description
Language Server Protocol implementation for Swift and C-based languages
Readme 14 MiB
Languages
Swift 97.3%
C 1.3%
CMake 0.7%
Python 0.7%