Skip to content

Commit

Permalink
Reconsider window log messages
Browse files Browse the repository at this point in the history
Also reconsider some log levels in TreeSitterParser
  • Loading branch information
jayadamsmorgan committed Apr 5, 2024
1 parent 9eb9f68 commit 381983a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
1 change: 1 addition & 0 deletions Sources/pkl-lsp/DocumentProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ public actor DocumentProvider {
let document = Document(textDocument: params.textDocument)
documents[documentUri] = document
await treeSitterParser.parse(document: document)
await sendClientWindowShowMessage(message: "PklLanguageServer: Ready", type: .info, document: document)

guard diagnosticsFeature.isEnabled else {
return
Expand Down
19 changes: 8 additions & 11 deletions Sources/pkl-lsp/TreeSitterParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public class TreeSitterParser {
tsParsedTrees[document] = tree
await parseAST(document: document, tree: tree)
logger.debug("Document \(document.uri) parsed.")
await documentProvider?.sendClientWindowShowMessage(message: "Done parsing.", type: .info, document: document)
}

private func parseFullyWithChanges(document: Document, params: DidChangeTextDocumentParams) async -> Document {
Expand All @@ -75,7 +74,7 @@ public class TreeSitterParser {
do {
edits = try Document.getTSInputEditsApplyingChanges(for: document, with: params.contentChanges, nextVersion: params.textDocument.version)
} catch {
logger.error("Failed to get TS Input Edits from document \(document.uri): \(error). Trying to parse document from scratch.")
logger.debug("Failed to get TS Input Edits from document \(document.uri): \(error). Trying to parse document from scratch.")
return await parseFullyWithChanges(document: document, params: params)
}
guard let edits else {
Expand All @@ -88,7 +87,7 @@ public class TreeSitterParser {
tree.edit(edit)
}
guard let newTree = parser.parse(tree: tree, string: newDocument.text) else {
logger.error("Failed to parse document \(newDocument.uri) with changes. New tree is nil.")
logger.debug("Failed to parse document \(newDocument.uri) with changes. New tree is nil.")
return document
}
if logger.logLevel == .trace {
Expand All @@ -105,7 +104,6 @@ public class TreeSitterParser {

private func parseAST(document: Document, tree: MutableTree, importDepth: Int = 0) async {
logger.debug("Parsing AST for document \(document.uri)")
await documentProvider?.sendClientWindowShowMessage(message: "Parsing AST for document \(document.uri)", type: .info, document: document)
guard let rootNode = tree.rootNode else {
logger.debug("No root node found for document \(document.uri)")
return
Expand All @@ -121,7 +119,6 @@ public class TreeSitterParser {
listASTNodes(rootNode: astRoot)
}
}
await documentProvider?.sendClientWindowShowMessage(message: "AST parsed for document \(document.uri)", type: .info, document: document)
}

private func parseVariableReferences(document: Document) async {
Expand Down Expand Up @@ -230,7 +227,7 @@ public class TreeSitterParser {
}
logger.debug("Module include: fileURL: \(fileURL.absoluteURL)")
guard let text = try? String(contentsOf: fileURL, encoding: .utf8) else {
logger.error("Module include: file not found: \(fileURL)")
logger.debug("Module include: file not found: \(fileURL)")
return nil
}
let document = Document(uri: fileURL.absoluteString, version: nil, text: text)
Expand All @@ -246,13 +243,13 @@ public class TreeSitterParser {
type: PklModuleImportType = .normal, parent: ASTNode?) async -> PklModuleImport?
{
guard let path else {
logger.error("Failed to parse path in building module import.")
logger.debug("Failed to parse path in building module import.")
return nil
}
path.type = .importString
path.value?.removeAll(where: { $0 == "\"" })
guard let pathValue = path.value else {
logger.error("Failed to parse path value in building module import.")
logger.debug("Failed to parse path value in building module import.")
return nil
}
let range = ASTRange(pointRange: node.pointRange, byteRange: node.byteRange)
Expand All @@ -270,7 +267,7 @@ public class TreeSitterParser {
}
importDocument = await includeModule(relPath: pathValue, currentDocument: document)
guard let importDocument else {
logger.error("Failed to include module \(pathValue) for document \(document.uri)")
logger.debug("Failed to include module \(pathValue) for document \(document.uri)")
return module
}
module.documentToImport = importDocument
Expand All @@ -280,7 +277,7 @@ public class TreeSitterParser {
return module
}
if importDepth >= maxImportDepth {
logger.error("Import depth exceeded for document \(document.uri)")
logger.debug("Import depth exceeded for document \(document.uri)")
return nil
}
if let tsTree = tsParsedTrees[importDocument] {
Expand Down Expand Up @@ -836,7 +833,7 @@ public class TreeSitterParser {
case .sym_importClause: // IMPORT CLAUSE
logger.debug("Starting building import clause...")
if importDepth > 3 {
logger.error("Import depth is too high.")
logger.debug("Import depth is too high.")
return nil
}
var path: PklStringLiteral?
Expand Down

0 comments on commit 381983a

Please sign in to comment.