-
Notifications
You must be signed in to change notification settings - Fork 59
Source file from in-memory string for incremental LSP analysis #1163
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
base: main
Are you sure you want to change the base?
Changes from 2 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,11 @@ public struct SourceFile { | |||||||
try self.init(contentsOf: URL(fileURLWithPath: filePath)) | ||||||||
} | ||||||||
|
||||||||
public init(filePath: URL, withContent content: String) { | ||||||||
let storage = Storage(filePath, replace: 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 +349,23 @@ extension SourceFile { | |||||||
} | ||||||||
|
||||||||
/// The owner of all instances of `Storage`. | ||||||||
private static var allInstances = SharedMutable<[URL: Storage]>([:]) | ||||||||
private static let allInstances = SharedMutable<[URL: Storage]>([:]) | ||||||||
|
||||||||
/// 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()`. | ||||||||
fileprivate convenience init( | ||||||||
_ url: URL, lineStarts: [Index]? = nil, makeText: () throws -> Substring | ||||||||
_ url: URL, lineStarts: [Index]? = nil, replace: 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 !replace && 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 | ||||||||
} | ||||||||
|
Uh oh!
There was an error while loading. Please reload this page.