Files
sourcekit-lsp/Sources/SKSupport/FileSystem.swift
Lokesh T R fd50560998 Add LSP support for @freestanding Macro Expansions.
------
Simplify `SemanticRefactoring` with new `Refactoring` protocol to handle sourcekitd requests

Create and implement `ExpandMacroCommand` while temporarily storing generated expansions.

Create test case `testFreestandingMacroExpansion`

Manually inject `ExpandMacroCommand` into `retrieveRefactorCodeActions` upon an "Inline Macro" from sourcekitd

Address Review Comments

Mark `@_spi(Testing) public` for `MacroExpansionEdit`

Address Review Comments

Create separate directory for each buffer with its name, containing a generated file named as the source file along with position range

Fixed generated macro expansion file extension not recognised, by switching to file names which don't contain fragments

Address Review Comments

Wrap the entire feature under `ExperimentalFeatures`

Address Review Comments

Make Swift Lint Pass

Fix Windows Build not passing
2024-06-20 18:14:45 +00:00

39 lines
1.4 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2018 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 struct TSCBasic.AbsolutePath
/// The home directory of the current user (same as returned by Foundation's `NSHomeDirectory` method).
public var homeDirectoryForCurrentUser: AbsolutePath {
try! AbsolutePath(validating: NSHomeDirectory())
}
extension AbsolutePath {
/// Inititializes an absolute path from a string, expanding a leading `~` to `homeDirectoryForCurrentUser` first.
public init(expandingTilde path: String) throws {
if path.first == "~" {
try self.init(homeDirectoryForCurrentUser, validating: String(path.dropFirst(2)))
} else {
try self.init(validating: path)
}
}
}
/// The default directory to write generated files
/// `<TEMPORARY_DIRECTORY>/sourcekit-lsp/`
public var defaultDirectoryForGeneratedFiles: AbsolutePath {
try! AbsolutePath(validating: NSTemporaryDirectory()).appending(component: "sourcekit-lsp")
}