Skip to content

Commit 90ab1d3

Browse files
Deprecate api endpoint
1 parent 0796cd2 commit 90ab1d3

6 files changed

Lines changed: 40 additions & 56 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
All notable changes to the "vscode-parse-tree" extension will be documented in this file.
44

5+
## 0.51.0 (12 Mar 2026)
6+
7+
Removed deprecated api endpoints:
8+
9+
- `getLanguage` - Replaced by `createQuery`
10+
- `getTreeForUri` - Replaced by `getTree`
11+
- `getNodeAtLocation` - No direct replacement. Use scm queries and `createQuery` instead.
12+
- `registerLanguage` - No replacement. We don't believe anyone is using this.
13+
514
## 0.33.0 (22 Apr 2025)
615

716
### Enhancements

README.md

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Parse tree
22

3-
Exposes an api function that can be used to get a parse tree node for a given file location.
3+
Exposes an api function that can be used to get a parse tree for a given file.
44

55
## Usage
66

@@ -13,25 +13,13 @@ if (parseTreeExtension == null) {
1313
throw new Error("Depends on pokey.parse-tree extension");
1414
}
1515

16-
const { getNodeAtLocation } = await parseTreeExtension.activate();
16+
const { loadLanguage } = await parseTreeExtension.activate();
1717
```
1818

1919
Don't forget to add an `extensionDependencies`-entry to `package.json` as
2020
described in
2121
https://code.visualstudio.com/api/references/vscode-api#extensions.
2222

23-
### Parsing a custom language
24-
25-
If you'd like to add support for a new language, see the [Adding a new language](#adding-a-new-language) section below. Alternatively, your extension can register a custom language with this extension. Although this is not the preferred way to add a new language, it can be convenient when you have a parser that you don't believe belongs in the main extension.
26-
27-
Parsing your own language is as simple as registering your `languageId` with an absolute path to your `.wasm` file:
28-
29-
```ts
30-
const { registerLanguage } = await parseTreeExtension.activate();
31-
32-
registerLanguage(languageId, wasmPath);
33-
```
34-
3523
## Contributing
3624

3725
### Setup

package-lock.json

Lines changed: 5 additions & 5 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
@@ -2,7 +2,7 @@
22
"name": "parse-tree",
33
"displayName": "Parse tree",
44
"description": "Access document syntax using tree-sitter",
5-
"version": "0.50.0",
5+
"version": "0.51.0",
66
"publisher": "pokey",
77
"repository": {
88
"type": "git",

src/errors.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,10 @@ export class LanguageStillLoadingError extends Error {
1313
this.name = "LanguageStillLoadingError";
1414
}
1515
}
16+
17+
export class DeprecatedError extends Error {
18+
constructor(name: string) {
19+
super(`${name} is deprecated and has been removed from the API`);
20+
this.name = "DeprecatedError";
21+
}
22+
}

src/extension.ts

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import * as semver from "semver";
44
import * as vscode from "vscode";
55
import * as treeSitter from "web-tree-sitter";
66
import { Edit } from "web-tree-sitter";
7-
import { LanguageStillLoadingError, UnsupportedLanguageError } from "./errors";
7+
import {
8+
DeprecatedError,
9+
LanguageStillLoadingError,
10+
UnsupportedLanguageError,
11+
} from "./errors";
812

913
interface Language {
1014
module: string;
@@ -294,15 +298,8 @@ export function activate(context: vscode.ExtensionContext) {
294298
return {
295299
loadLanguage,
296300

297-
/**
298-
* @deprecated
299-
*/
300-
getLanguage(languageId: string): treeSitter.Language | undefined {
301-
console.warn(
302-
"vscode-parse-tree: getLanguage is deprecated, use createQuery(languageId, source) instead.",
303-
);
304-
validateGetLanguage(languageId);
305-
return languages[languageId]?.parser?.language ?? undefined;
301+
getTree(document: vscode.TextDocument) {
302+
return getTreeForUri(document.uri);
306303
},
307304

308305
createQuery(
@@ -317,34 +314,17 @@ export function activate(context: vscode.ExtensionContext) {
317314
return new treeSitter.Query(language, source);
318315
},
319316

320-
/**
321-
* Register a parser wasm file for a language not supported by this
322-
* extension. Note that {@link wasmPath} must be an absolute path, and
323-
* {@link languageId} must not already have a registered parser.
324-
* @param languageId The VSCode language id that you'd like to register a
325-
* parser for
326-
* @param wasmPath The absolute path to the wasm file for your parser
327-
*/
328-
registerLanguage(languageId: string, wasmPath: string) {
329-
if (languages[languageId] != null) {
330-
throw new Error(`Language id '${languageId}' is already registered`);
331-
}
332-
333-
languages[languageId] = { module: wasmPath };
334-
void colorAllOpen();
317+
getLanguage(): treeSitter.Language | undefined {
318+
throw new DeprecatedError("getLanguage");
335319
},
336-
337-
getTree(document: vscode.TextDocument) {
338-
return getTreeForUri(document.uri);
320+
getTreeForUri() {
321+
throw new DeprecatedError("getTreeForUri");
339322
},
340-
341-
getTreeForUri,
342-
343-
getNodeAtLocation(location: vscode.Location) {
344-
return getTreeForUri(location.uri).rootNode.descendantForPosition({
345-
row: location.range.start.line,
346-
column: location.range.start.character,
347-
});
323+
getNodeAtLocation() {
324+
throw new DeprecatedError("getNodeAtLocation");
325+
},
326+
registerLanguage() {
327+
throw new DeprecatedError("registerLanguage");
348328
},
349329
};
350330
}

0 commit comments

Comments
 (0)