Skip to content

Commit

Permalink
Refactor semantic token walker to use explicit traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
koliyo committed Sep 29, 2023
1 parent f3b3365 commit 6610f08
Show file tree
Hide file tree
Showing 6 changed files with 721 additions and 656 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import FrontEnd
import IR

extension AST {
struct NodeFinder: ASTWalkObserver {
private struct NodeFinder: ASTWalkObserver {
// var outermostFunctions: [FunctionDecl.ID] = []
let query: SourcePosition
private(set) var match: AnyNodeID?
Expand Down
43 changes: 43 additions & 0 deletions Sources/hylo-lsp/AST+FindTranslationUnit.swift
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
}
}
Loading

0 comments on commit 6610f08

Please sign in to comment.