Skip to content

Commit

Permalink
Update tree-sitter, tree-sitter-fluentbit, etc. (#6)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sh-cho authored Sep 15, 2024
1 parent 4c4430c commit 576b339
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
]
Expand Down
29 changes: 22 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions clients/vscode/src/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -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;
// }
29 changes: 3 additions & 26 deletions clients/vscode/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion clients/vscode/syntaxes/fluent-bit.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
41 changes: 23 additions & 18 deletions flb-schema/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions fluent-bit-language-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions fluent-bit-language-server/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions fluent-bit-language-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ async fn main() {
})
.finish();

// TODO: support other commands (e.g. `--version`)

Server::new(stdin, stdout, socket).serve(service).await;
}

0 comments on commit 576b339

Please sign in to comment.