mirror of
https://github.com/apple/sourcekit-lsp.git
synced 2026-03-06 18:24:36 +01:00
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.
97 lines
3.5 KiB
Swift
97 lines
3.5 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 IndexStoreDB
|
|
import LSPTestSupport
|
|
import LanguageServerProtocol
|
|
import SKCore
|
|
import SKTestSupport
|
|
import SourceKitLSP
|
|
import XCTest
|
|
|
|
final class MainFilesProviderTests: XCTestCase {
|
|
|
|
func testMainFilesChanged() async throws {
|
|
let ws = try await mutableSourceKitTibsTestWorkspace(name: "MainFiles")!
|
|
let indexDelegate = SourceKitIndexDelegate()
|
|
ws.tibsWorkspace.delegate = indexDelegate
|
|
|
|
final class TestMainFilesDelegate: MainFilesDelegate {
|
|
var expectation: XCTestExpectation
|
|
init(_ expectation: XCTestExpectation) { self.expectation = expectation }
|
|
func mainFilesChanged() {
|
|
expectation.fulfill()
|
|
}
|
|
}
|
|
|
|
let mainFilesDelegate = TestMainFilesDelegate(expectation(description: "main files changed"))
|
|
indexDelegate.registerMainFileChanged(mainFilesDelegate)
|
|
|
|
let a = ws.testLoc("a_func").docIdentifier.uri
|
|
let b = ws.testLoc("b_func").docIdentifier.uri
|
|
let c = ws.testLoc("c_func").docIdentifier.uri
|
|
let d = ws.testLoc("d_func").docIdentifier.uri
|
|
let unique_h = ws.testLoc("unique").docIdentifier.uri
|
|
let shared_h = ws.testLoc("shared").docIdentifier.uri
|
|
let bridging = ws.testLoc("bridging").docIdentifier.uri
|
|
|
|
XCTAssertEqual(ws.index.mainFilesContainingFile(a), [])
|
|
XCTAssertEqual(ws.index.mainFilesContainingFile(b), [])
|
|
XCTAssertEqual(ws.index.mainFilesContainingFile(c), [])
|
|
XCTAssertEqual(ws.index.mainFilesContainingFile(d), [])
|
|
XCTAssertEqual(ws.index.mainFilesContainingFile(unique_h), [])
|
|
XCTAssertEqual(ws.index.mainFilesContainingFile(shared_h), [])
|
|
XCTAssertEqual(ws.index.mainFilesContainingFile(bridging), [])
|
|
|
|
try ws.buildAndIndex()
|
|
|
|
XCTAssertEqual(ws.index.mainFilesContainingFile(a), [a])
|
|
XCTAssertEqual(ws.index.mainFilesContainingFile(b), [b])
|
|
XCTAssertEqual(ws.index.mainFilesContainingFile(c), [c])
|
|
XCTAssertEqual(ws.index.mainFilesContainingFile(d), [d])
|
|
XCTAssertEqual(ws.index.mainFilesContainingFile(unique_h), [d])
|
|
XCTAssertEqual(ws.index.mainFilesContainingFile(shared_h), [c, d])
|
|
XCTAssertEqual(ws.index.mainFilesContainingFile(bridging), [c])
|
|
|
|
try await fulfillmentOfOrThrow([mainFilesDelegate.expectation])
|
|
|
|
try ws.edit { changes, _ in
|
|
changes.write(
|
|
"""
|
|
#include "bridging.h"
|
|
void d_new(void) { bridging(); }
|
|
""",
|
|
to: d.fileURL!
|
|
)
|
|
|
|
changes.write(
|
|
"""
|
|
#include "unique.h"
|
|
void c_new(void) { unique(); }
|
|
""",
|
|
to: c.fileURL!
|
|
)
|
|
}
|
|
|
|
mainFilesDelegate.expectation = expectation(description: "main files changed after edit")
|
|
try ws.buildAndIndex()
|
|
|
|
XCTAssertEqual(ws.index.mainFilesContainingFile(unique_h), [c])
|
|
XCTAssertEqual(ws.index.mainFilesContainingFile(shared_h), [])
|
|
XCTAssertEqual(ws.index.mainFilesContainingFile(bridging), [d])
|
|
|
|
try await fulfillmentOfOrThrow([mainFilesDelegate.expectation])
|
|
|
|
XCTAssertEqual(ws.index.mainFilesContainingFile(DocumentURI(string: "not:file")), [])
|
|
}
|
|
}
|