mirror of
https://github.com/apple/sourcekit-lsp.git
synced 2026-03-02 18:23:24 +01:00
The idea here is to unify the different ways in which we can currently set options on SourceKit-LSP in a scalable way: Environment variables, command line arguments to `sourcekit-lsp` and initialization options. The idea is that a user can define a `~/.sourcekit-lsp/.sourcekit-lsp` file (we store logs in `~/.sourcekit-lsp/logs` on non-Darwin platforms), which will be used as the default configuration for all SourceKit-LSP instances. They can also place a `.sourcekit-lsp` file in the root of a workspace to configure SourceKit-LSP for that project specifically, eg. setting arguments that need to be passed to `swift build` for that project and which thus also need to be set on SourceKit-LSP. For compatibility reasons, I’m mapping the existing command line options into the new options structure for now. I hope to delete the command line arguments in the future and solely rely on `.sourcekit-lsp` configuration files. Environment variable will be migrated to `.sourcekit-lsp` in a follow-up commit. # Conflicts: # Sources/SourceKitLSP/SourceKitLSPServer+Options.swift # Sources/SourceKitLSP/Swift/SwiftLanguageService.swift # Sources/sourcekit-lsp/SourceKitLSP.swift # Tests/SourceKitLSPTests/BackgroundIndexingTests.swift # Tests/SourceKitLSPTests/ExecuteCommandTests.swift
46 lines
1.8 KiB
Swift
46 lines
1.8 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import Foundation
|
|
import LSPLogging
|
|
import LanguageServerProtocol
|
|
import SourceKitD
|
|
import SwiftBasicFormat
|
|
|
|
extension SwiftLanguageService {
|
|
public func completion(_ req: CompletionRequest) async throws -> CompletionList {
|
|
let snapshot = try documentManager.latestSnapshot(req.textDocument.uri)
|
|
|
|
let completionPos = await adjustPositionToStartOfIdentifier(req.position, in: snapshot)
|
|
let offset = snapshot.utf8Offset(of: completionPos)
|
|
let filterText = String(snapshot.text[snapshot.indexOf(utf8Offset: offset)..<snapshot.index(of: req.position)])
|
|
|
|
let clientSupportsSnippets =
|
|
capabilityRegistry.clientCapabilities.textDocument?.completion?.completionItem?.snippetSupport ?? false
|
|
let buildSettings = await buildSettings(for: snapshot.uri)
|
|
|
|
let inferredIndentationWidth = BasicFormat.inferIndentation(of: await syntaxTreeManager.syntaxTree(for: snapshot))
|
|
|
|
return try await CodeCompletionSession.completionList(
|
|
sourcekitd: sourcekitd,
|
|
snapshot: snapshot,
|
|
indentationWidth: inferredIndentationWidth,
|
|
completionPosition: completionPos,
|
|
completionUtf8Offset: offset,
|
|
cursorPosition: req.position,
|
|
compileCommand: buildSettings,
|
|
clientSupportsSnippets: clientSupportsSnippets,
|
|
filterText: filterText
|
|
)
|
|
}
|
|
}
|