Skip to content

Support rename across Swift files #993

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

Merged
merged 6 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Sources/SKSupport/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ add_library(SKSupport STATIC
AsyncUtils.swift
BuildConfiguration.swift
ByteString.swift
Collection+Only.swift
Connection+Send.swift
dlopen.swift
FileSystem.swift
Expand Down
22 changes: 22 additions & 0 deletions Sources/SKSupport/Collection+Only.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2023 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
//
//===----------------------------------------------------------------------===//

public extension Collection {
/// If the collection contains a single element, return it, otherwise `nil`.
var only: Element? {
if !isEmpty && index(after: startIndex) == endIndex {
return self.first!
} else {
return nil
}
}
}
5 changes: 5 additions & 0 deletions Sources/SKTestSupport/TestSourceKitLSPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ public struct DocumentPositions {
}
return position
}

/// Returns all position makers within these `DocumentPositions`.
public var allMarkers: [String] {
return positions.keys.sorted()
}
}

// MARK: - WeakMessageHelper
Expand Down
6 changes: 6 additions & 0 deletions Sources/SourceKitD/SKDRequestArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public final class SKDRequestArray {
public func append(_ value: SKDRequestDictionary) {
sourcekitd.api.request_array_set_value(array, -1, value.dict)
}

public static func += (array: SKDRequestArray, other: some Sequence<SKDRequestDictionary>) {
for item in other {
array.append(item)
}
}
}

extension SKDRequestArray: CustomStringConvertible {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SourceKitLSP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ add_library(SourceKitLSP STATIC
DocumentManager.swift
IndexStoreDB+MainFilesProvider.swift
ResponseError+Init.swift
Rename.swift
Sequence+AsyncMap.swift
SourceKitIndexDelegate.swift
SourceKitLSPCommandMetadata.swift
Expand All @@ -25,7 +26,6 @@ target_sources(SourceKitLSP PRIVATE
Swift/EditorPlaceholder.swift
Swift/OpenInterface.swift
Swift/RelatedIdentifiers.swift
Swift/Rename.swift
Swift/SemanticRefactorCommand.swift
Swift/SemanticRefactoring.swift
Swift/SemanticTokens.swift
Expand Down
4 changes: 0 additions & 4 deletions Sources/SourceKitLSP/Clang/ClangLanguageServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,6 @@ extension ClangLanguageServerShim {
func executeCommand(_ req: ExecuteCommandRequest) async throws -> LSPAny? {
return try await forwardRequestToClangd(req)
}

func rename(_ request: RenameRequest) async throws -> WorkspaceEdit? {
return try await forwardRequestToClangd(request)
}
}

/// Clang build settings derived from a `FileBuildSettingsChange`.
Expand Down
Loading