-
-
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.
perf(server): smarter tree-sitter parsing
- Loading branch information
1 parent
ddc45f4
commit 24e1cda
Showing
4 changed files
with
29 additions
and
8 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
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 |
---|---|---|
@@ -1,12 +1,28 @@ | ||
import TSParser from "tree-sitter"; | ||
import Publicodes from "tree-sitter-publicodes"; | ||
import { TextDocument } from "vscode-languageserver-textdocument"; | ||
import { FileInfos } from "./context"; | ||
|
||
const parser = new TSParser(); | ||
parser.setLanguage(Publicodes); | ||
|
||
export function tsParseText( | ||
/** | ||
* Parse the content of the document with the tree-sitter parser if the | ||
* document has changed since the last parse. | ||
* | ||
* @param content - The content of the document to parse | ||
* @param fileInfos - The file infos to check if the document has changed | ||
* @param document - The document to get the version from | ||
* | ||
* @returns The tree-sitter tree of the document | ||
*/ | ||
export function getTSTree( | ||
content: string, | ||
currentTree?: TSParser.Tree | undefined, | ||
fileInfos: FileInfos | undefined, | ||
document: TextDocument | undefined, | ||
): TSParser.Tree { | ||
return parser.parse(content, currentTree); | ||
if (fileInfos?.version && fileInfos.version === document?.version) { | ||
return fileInfos.tsTree; | ||
} | ||
return parser.parse(content); | ||
} |