-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring code to match bash-language-server
- Can parse active document - Logging functionality
- Loading branch information
1 parent
aa3e113
commit e6dae18
Showing
7 changed files
with
288 additions
and
228 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,45 @@ | ||
/* -------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2023 Andreas Heuermann, Osman Karabel | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
* ------------------------------------------------------------------------------------------ */ | ||
|
||
import * as LSP from 'vscode-languageserver/node'; | ||
import { TextDocument } from 'vscode-languageserver-textdocument'; | ||
|
||
import { Query } from 'web-tree-sitter'; | ||
import Parser = require('web-tree-sitter'); | ||
|
||
import { logger } from './util/logger'; | ||
|
||
type AnalyzedDocument = { | ||
document: TextDocument; | ||
tree: Parser.Tree | ||
} | ||
|
||
export default class Analyzer { | ||
private parser: Parser; | ||
private uriToAnalyzedDocument: Record<string, AnalyzedDocument | undefined> = {}; | ||
|
||
constructor (parser: Parser) { | ||
this.parser = parser; | ||
} | ||
|
||
public analyze(document: TextDocument): LSP.Diagnostic[] { | ||
logger.debug('analyze:'); | ||
|
||
const diagnostics: LSP.Diagnostic[] = []; | ||
const fileContent = document.getText(); | ||
const uri = document.uri; | ||
|
||
const tree = this.parser.parse(fileContent); | ||
logger.debug(tree.rootNode.toString()); | ||
|
||
// Update saved analysis for document uri | ||
this.uriToAnalyzedDocument[uri] = { | ||
document, | ||
tree | ||
}; | ||
|
||
return diagnostics; | ||
} | ||
} |
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
Oops, something went wrong.