From 9a3ff05ea314cf1e7b04ea72e8649463fc365317 Mon Sep 17 00:00:00 2001 From: Emile Rolley Date: Sat, 6 Jul 2024 16:13:24 +0200 Subject: [PATCH] feat: add support for '.publicodes.yaml' and '.publicodes.yml' file extensions --- README.md | 2 +- package.json | 4 +++- server/src/initialize.ts | 8 ++++++-- server/src/parseRules.ts | 8 ++++++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 08c08d0..cfa3129 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ A VSCode extension providing language server capabilities for - 💡 Go to definition - 🔍 Hover information (resolved name, current node value and description) -> Recognized extension files are: `.publicodes` +> Recognized extension files are: `.publicodes`, `.publicodes.yaml`, `.publicodes.yml` ## Syntax Highlighting Configuration diff --git a/package.json b/package.json index 2552b96..8ef5b06 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,9 @@ "Publicodes" ], "extensions": [ - ".publicodes" + ".publicodes", + ".publicodes.yaml", + ".publicodes.yml" ], "configuration": "./language-configuration.json", "icon": { diff --git a/server/src/initialize.ts b/server/src/initialize.ts index 726cab8..faee2ec 100644 --- a/server/src/initialize.ts +++ b/server/src/initialize.ts @@ -5,6 +5,7 @@ import { } from "vscode-languageserver/node.js"; import { GlobalConfig } from "./context"; import { tokenModifiers, tokenTypes } from "./semanticTokens"; +import { PUBLICODES_FILE_EXTENSIONS } from "./parseRules"; export default function initialize(params: InitializeParams): { config: GlobalConfig; @@ -50,17 +51,20 @@ export default function initialize(params: InitializeParams): { }, }, }; + if (hasWorkspaceFolderCapability) { + const globPublicodesFiles = `**/*.{${PUBLICODES_FILE_EXTENSIONS.join(",")}}`; + initResult.capabilities.workspace = { workspaceFolders: { supported: true, }, fileOperations: { didDelete: { - filters: [{ scheme: "file", pattern: { glob: "**/*.publicodes" } }], + filters: [{ scheme: "file", pattern: { glob: globPublicodesFiles } }], }, didRename: { - filters: [{ scheme: "file", pattern: { glob: "**/*.publicodes" } }], + filters: [{ scheme: "file", pattern: { glob: globPublicodesFiles } }], }, }, }; diff --git a/server/src/parseRules.ts b/server/src/parseRules.ts index cdeb5e4..b1a14e1 100644 --- a/server/src/parseRules.ts +++ b/server/src/parseRules.ts @@ -16,7 +16,11 @@ import { import { getTSTree } from "./treeSitter"; import { mapAppend, positionToRange, trimQuotedString } from "./helpers"; -const PUBLICODES_FILE_EXTENSION = ".publicodes"; +export const PUBLICODES_FILE_EXTENSIONS = [ + ".publicodes", + ".publicodes.yaml", + ".publicodes.yml", +]; /** * Explore recursively all files in the workspace folder and concat all yaml @@ -33,7 +37,7 @@ export function parseDir(ctx: LSContext, uri: string) { return; } const filePath = join(path, file); - if (filePath.endsWith(PUBLICODES_FILE_EXTENSION)) { + if (PUBLICODES_FILE_EXTENSIONS.find((ext) => filePath.endsWith(ext))) { parseDocument( ctx, filePath,