Skip to content

Commit a3d3fce

Browse files
committed
Fix console errors
1 parent 0b70263 commit a3d3fce

File tree

7 files changed

+17
-11
lines changed

7 files changed

+17
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,4 @@ Highlights scope names with their own themed colour in realtime:
8484
* Move to LanguageServer
8585
* Add unit tests
8686
* Improve TreeSitter Query performance: [Node contains `&fieldName`](https://github.com/tree-sitter/tree-sitter/issues/3956), [Caching or Serializing a `TSQuery`](https://github.com/tree-sitter/tree-sitter/issues/1942)
87+
* use strict `null` checks

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@
365365
},
366366
"dependencies": {
367367
"vscode-oniguruma": "1.7.0",
368-
"web-tree-sitter": "^0.24.4"
368+
"web-tree-sitter": "^0.24.3"
369369
},
370370
"devDependencies": {
371371
"@types/vscode": "^1.87.0",

src/DiagnosticCollection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ function diagnosticsTreeSitterJSONErrors(diagnostics: vscode.Diagnostic[], rootN
115115
continue;
116116
}
117117
diagnostic = {
118-
range: toRange(node.previousSibling.endPosition, node.previousSibling.endPosition),
118+
range: toRange(node.previousSibling.endPosition),
119119
message: `'${parentType}' is missing character${type.length > 1 ? 's' : ''} '${type}'`,
120120
severity: vscode.DiagnosticSeverity.Error,
121121
source: 'TreeSitter',

src/Providers/HoverProvider.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export const HoverProvider: vscode.HoverProvider = {
1818
(while (key) @while)
1919
`;
2020
const hoverCapture = queryNode(rootNode, hoverQuery, point);
21+
if (!hoverCapture) {
22+
return;
23+
}
24+
2125
const hoverNode = hoverCapture.node;
2226

2327
const markdownString = new vscode.MarkdownString();
@@ -71,7 +75,7 @@ function debugTreeSitterHovers(trees: trees, point: Point): vscode.Hover {
7175
const node = trees.jsonTree.rootNode.descendantForPosition(point);
7276
// const node = jsonTree.rootNode.namedDescendantForPosition(point);
7377

74-
if (node == null) {
78+
if (!node) {
7579
return;
7680
}
7781

src/TreeSitter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,14 @@ export function queryNode(node: Parser.SyntaxNode, queryString: string, startPoi
148148
}
149149

150150
export function toRange(node: Parser.SyntaxNode): vscode.Range;
151+
export function toRange(points: Parser.Point): vscode.Range;
151152
export function toRange(start: Parser.Point, end: Parser.Point): vscode.Range;
152153
export function toRange(node: Parser.SyntaxNode | Parser.Point, end?: Parser.Point): vscode.Range {
153154
if (!node) {
154155
return null;
155156
}
156157
const startPosition = 'startPosition' in node ? node.startPosition : node;
157-
const endPosition = 'startPosition' in node ? node.endPosition : end;
158+
const endPosition = 'endPosition' in node ? node.endPosition : end || startPosition;
158159
const range = new vscode.Range(
159160
startPosition.row,
160161
startPosition.column,

src/extension.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ https://www.npmjs.com/package/json-cst
176176
export async function getPackageJSON(baseUri: vscode.TextDocument | vscode.Uri, ...pathSegments: string[]) {
177177
if ('isUntitled' in baseUri) {
178178
if (baseUri.isUntitled) {
179-
return null;
179+
return {};
180180
}
181181
}
182182

@@ -190,7 +190,7 @@ export async function getPackageJSON(baseUri: vscode.TextDocument | vscode.Uri,
190190

191191
const file = file1 || await vscode.workspace.fs.readFile(packageUri2).then(null, () => { });
192192
if (!file) {
193-
return null;
193+
return {};
194194
}
195195

196196
try {
@@ -205,5 +205,5 @@ export async function getPackageJSON(baseUri: vscode.TextDocument | vscode.Uri,
205205
console.warn(`TextMate: Failed to parse package.json\n${error}`);
206206
}
207207

208-
return null;
208+
return {};
209209
}

0 commit comments

Comments
 (0)