Update tree-sitter, tree-sitter-fluentbit, etc. (#6)

* Update tree-sitter 0.23.0, tree-sitter-fluentbit 0.1.0

* Fix plugin deserialize test

* Update tmLanguage to support hyphen in key

* Support debug build
This commit is contained in:
Seonghyeon Cho 2024-09-15 17:23:02 +09:00 committed by GitHub
parent 4c4430c4a7
commit 576b339db6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 123 additions and 57 deletions

2
.vscode/launch.json vendored
View file

@ -17,7 +17,7 @@
"<node_internals>/**/*.js"
],
"env": {
"SERVER_PATH": "${workspaceFolder}/target/debug/fluent-bit-language-server"
"__FLB_LSP_SERVER_DEBUG": "${workspaceFolder}/target/debug/fluent-bit-language-server"
}
}
]

29
Cargo.lock generated
View file

@ -206,12 +206,13 @@ dependencies = [
[[package]]
name = "cc"
version = "1.1.7"
version = "1.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26a5c3fd7bfa1ce3897a3a3501d362b2d87b7f2583ebcb4a949ec25911025cbc"
checksum = "b62ac837cdb5cb22e10a256099b4fc502b1dfe560cb282963a974d7abd80e476"
dependencies = [
"jobserver",
"libc",
"shlex",
]
[[package]]
@ -1043,6 +1044,12 @@ dependencies = [
"digest",
]
[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "signal-hook-registry"
version = "1.4.2"
@ -1301,24 +1308,32 @@ dependencies = [
[[package]]
name = "tree-sitter"
version = "0.22.6"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df7cc499ceadd4dcdf7ec6d4cbc34ece92c3fa07821e287aedecd4416c516dca"
checksum = "20f4cd3642c47a85052a887d86704f4eac272969f61b686bdd3f772122aabaff"
dependencies = [
"cc",
"regex",
"regex-syntax",
"tree-sitter-language",
]
[[package]]
name = "tree-sitter-fluentbit"
version = "0.1.0-alpha.4"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64f5f073111c9de7b6d1fc700f03a317b5d2513ae71eb81f4ff5644cd4af0c9f"
checksum = "1ccb963c3c5c4cb1520fad7bdfc982d882f8e777285b9ec89715dc9a6ec224ba"
dependencies = [
"cc",
"tree-sitter",
"tree-sitter-language",
]
[[package]]
name = "tree-sitter-language"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2545046bd1473dac6c626659cc2567c6c0ff302fc8b84a56c4243378276f7f57"
[[package]]
name = "typenum"
version = "1.17.0"

View file

@ -0,0 +1,67 @@
import * as vscode from "vscode";
import * as os from "os";
export async function bootstrap(
context: vscode.ExtensionContext
): Promise<string> {
const path = await getServers(context);
if (!path) {
throw new Error("fluent-bit-language-server is not available.");
}
console.log("Using server binary at", path);
// TODO: check validity
return path;
}
async function getServers(
context: vscode.ExtensionContext
): Promise<string | undefined> {
// check if the server path is configured explicitly
const explicitPath = process.env["__FLB_LSP_SERVER_DEBUG"];
if (explicitPath) {
if (explicitPath.startsWith("~/")) {
return os.homedir() + explicitPath.slice("~".length);
}
return explicitPath;
}
const ext = process.platform === "win32" ? ".exe" : "";
const bundled = vscode.Uri.joinPath(context.extensionUri, "server", `fluent-bit-language-server${ext}`);
const bundledExists = await fileExists(bundled);
if (!bundledExists) {
await vscode.window.showErrorMessage(
"Unfortunately we don't ship binaries for your platform yet. " +
"Please build and run the server manually from the source code. " +
"Or, please create an issue on repository."
);
return;
}
}
async function fileExists(uri: vscode.Uri) {
return await vscode.workspace.fs.stat(uri).then(
() => true,
() => false,
);
}
// TODO
// export function isValidExecutable(path: string, extraEnv: Env): boolean {
// log.debug("Checking availability of a binary at", path);
// const res = spawnSync(path, ["--version"], {
// encoding: "utf8",
// env: { ...process.env, ...extraEnv },
// });
// if (res.error) {
// log.warn(path, "--version:", res);
// } else {
// log.info(path, "--version:", res);
// }
// return res.status === 0;
// }

View file

@ -9,31 +9,15 @@ import {
LanguageClientOptions,
ServerOptions,
} from "vscode-languageclient/node";
import * as vscode from "vscode";
import { bootstrap } from "./bootstrap";
let client: LanguageClient;
export async function activate(context: ExtensionContext) {
// TODO: bootstrap debug, release
// const traceOutputChannel = window.createOutputChannel("fluent-bit language server trace");
// const command = process.env.SERVER_PATH || "fluent-bit-language-server";
// Use bundled server only for now
const ext = process.platform === "win32" ? ".exe" : "";
const bundled = vscode.Uri.joinPath(context.extensionUri, "server", `fluent-bit-language-server${ext}`);
const bundledExists = await fileExists(bundled);
if (!bundledExists) {
await vscode.window.showErrorMessage(
"Unfortunately we don't ship binaries for your platform yet." +
"Please build and run the server manually from the source code." +
"Or, please create an issue on repository."
);
return;
}
const path = await bootstrap(context);
const run: Executable = {
command: bundled.fsPath,
command: path,
options: {
env: {
...process.env
@ -70,13 +54,6 @@ export async function activate(context: ExtensionContext) {
await client.start();
}
async function fileExists(uri: vscode.Uri) {
return await vscode.workspace.fs.stat(uri).then(
() => true,
() => false,
);
}
export function deactivate(): Thenable<void> | undefined {
if (!client) {
return undefined;

View file

@ -71,7 +71,7 @@
"patterns": [
{
"name": "keyword.other.entry.fluent-bit",
"match": "^\\s*\\b\\w+(\\.\\w+)*\\b\\s+"
"match": "^\\s*\\b[A-Za-z0-9_-]+(\\.[A-Za-z0-9_-]+)*\\b\\s+"
},
{
"name": "comment.line.number-sign.fluent-bit",

View file

@ -245,30 +245,35 @@ mod tests {
fn flb_plugin_deserialize() {
let plugin: FlbPlugin = serde_json::from_str(
r#"{
"options": [
{
"name": "host",
"description": "Host Address",
"default": "",
"type": "string"
}
],
"networking": [
{
"name": "net.dns.mode",
"description": "Select the primary DNS connection type (TCP or UDP)",
"default": null,
"type": "string"
}
]
"type": "custom",
"name": "vince",
"description": "this is vince plugin",
"properties": {
"options": [
{
"name": "host",
"description": "Host Address",
"default": "",
"type": "string"
}
],
"networking": [
{
"name": "net.dns.mode",
"description": "Select the primary DNS connection type (TCP or UDP)",
"default": null,
"type": "string"
}
]
}
}"#,
)
.unwrap();
assert_eq!(plugin, FlbPlugin {
type_: FlbSectionType::Custom,
name: "custom".to_string(),
description: "custom".to_string(),
name: "vince".to_string(),
description: "this is vince plugin".to_string(),
properties: vec![FlbProperty {
type_: FlbPropertyType::String,
name: "host".to_string(),

View file

@ -14,8 +14,8 @@ name = "fluent-bit-language-server"
[dependencies]
anyhow.workspace = true
convert_case.workspace = true
tree-sitter = "0.22.6"
tree-sitter-fluentbit = "0.1.0-alpha.4"
tree-sitter = "0.23.0"
tree-sitter-fluentbit = "0.1.0"
tower-lsp = "0.20.0"
tokio = { version = "1.38.0", features = ["full"] }
once_cell = "1.19.0"

View file

@ -35,10 +35,10 @@ impl TextDocument {
let rope = Rope::from_str(text);
let mut parser = Parser::new();
let language = tree_sitter_fluentbit::language();
let language = tree_sitter_fluentbit::LANGUAGE;
parser
.set_language(&language)
.set_language(&language.into())
.expect("set parser language should always succeed");
let tree = parser

View file

@ -21,5 +21,7 @@ async fn main() {
})
.finish();
// TODO: support other commands (e.g. `--version`)
Server::new(stdin, stdout, socket).serve(service).await;
}