-
Notifications
You must be signed in to change notification settings - Fork 59
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
Source file from in-memory string for incremental LSP analysis #1163
base: main
Are you sure you want to change the base?
Changes from 5 commits
8f1309d
467cbfa
0b3724f
435902b
7cf2428
8fbc575
0e5e803
0f0c3fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -33,6 +33,14 @@ public struct SourceFile { | |||||||
try self.init(contentsOf: URL(fileURLWithPath: filePath)) | ||||||||
} | ||||||||
|
||||||||
/// Creates an instance representing the in-memory edited file at `filePath`. | ||||||||
/// `withContent` is the content of the in-memory representation of the file, | ||||||||
/// which may be different from what is actually stored on disk. | ||||||||
public init(at filePath: URL, withContent content: String) { | ||||||||
let storage = Storage(filePath, replaceExisting: true) { content[...] } | ||||||||
self.storage = storage | ||||||||
} | ||||||||
|
||||||||
/// Creates an instance for the `text` given by a multiline string literal in the given | ||||||||
/// `swiftFile`, the literal's textual content (the line after the opening quotes) being | ||||||||
/// startLine. | ||||||||
|
@@ -344,17 +352,26 @@ extension SourceFile { | |||||||
} | ||||||||
|
||||||||
/// The owner of all instances of `Storage`. | ||||||||
private static var allInstances = SharedMutable<[URL: Storage]>([:]) | ||||||||
private static let allInstances = SharedMutable<[URL: Storage]>([:]) | ||||||||
dabrahams marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
|
||||||||
/// Creates an alias to the instance with the given `url` if it exists, or creates a new | ||||||||
/// instance having the given `url` and the text resulting from `makeText()`. | ||||||||
/// Storage instances are cached based on url, where `replaceExisting` defines if an | ||||||||
/// existing entry should be replaced with new content, otherwise the storage get the | ||||||||
/// content from the previously cached entry. | ||||||||
koliyo marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
fileprivate convenience init( | ||||||||
_ url: URL, lineStarts: [Index]? = nil, makeText: () throws -> Substring | ||||||||
_ url: URL, lineStarts: [Index]? = nil, replaceExisting: Bool = false, makeText: () throws -> Substring | ||||||||
) rethrows { | ||||||||
self.init( | ||||||||
aliasing: try Self.allInstances.modify { (c: inout [URL: Storage]) -> Storage in | ||||||||
try modify(&c[url]) { v in | ||||||||
let r = try v ?? Storage(url: url, lineStarts: lineStarts, text: makeText()) | ||||||||
let r: Storage | ||||||||
if !replaceExisting && v != nil { | ||||||||
r = v! | ||||||||
} | ||||||||
else { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think swift-format won't like the newline anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sf allows discretionary newlines. As you know this style often creates harmful vertical density. Why push for it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. swift-format will rewrite this. I just checked again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uh, yeah; this it's not the tool I thought it was. |
||||||||
r = try Storage(url: url, lineStarts: lineStarts, text: makeText()) | ||||||||
} | ||||||||
v = r | ||||||||
return r | ||||||||
} | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note:
contents
with a "s" is consistent with how other parameters are named.