-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor semantic token walker to use explicit traversal
- Loading branch information
Showing
6 changed files
with
721 additions
and
656 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import Foundation | ||
import Core | ||
import FrontEnd | ||
import IR | ||
import LanguageServerProtocol | ||
|
||
extension AST { | ||
private struct TranslationUnitFinder: ASTWalkObserver { | ||
// var outermostFunctions: [FunctionDecl.ID] = [] | ||
let query: DocumentUri | ||
private(set) var match: TranslationUnit? | ||
|
||
|
||
public init(_ query: DocumentUri) { | ||
self.query = query | ||
} | ||
|
||
mutating func willEnter(_ n: AnyNodeID, in ast: AST) -> Bool { | ||
let node = ast[n] | ||
let site = node.site | ||
|
||
if let t = node as? TranslationUnit { | ||
if site.file.url.absoluteString == query { | ||
match = t | ||
} | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
} | ||
|
||
public func findTranslationUnit(_ url: DocumentUri) -> TranslationUnit? { | ||
var finder = TranslationUnitFinder(url) | ||
for m in modules { | ||
walk(m, notifying: &finder) | ||
if finder.match != nil { | ||
break | ||
} | ||
} | ||
return finder.match | ||
} | ||
} |
Oops, something went wrong.