From 83bba952cb40a24010553e34fe55e12e24f46852 Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Sat, 8 Feb 2025 08:47:18 +0100 Subject: [PATCH] Add language extension debugging --- .gitignore | 2 ++ .vscode/launch.json | 19 +++++++++++++ .vscode/tasks.json | 11 ++++++++ language-configuration.json | 28 ++++++++++++++++++++ package-lock.json | 3 +++ package.json | 26 ++++++++++++++++++ testing-util/prepare-extension-debugging.mjs | 14 ++++++++++ 7 files changed, 103 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json create mode 100644 language-configuration.json create mode 100644 testing-util/prepare-extension-debugging.mjs diff --git a/.gitignore b/.gitignore index 3c3629e..dfacd87 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ node_modules +grammars/css.tmLanguage.json +testing-util/example.css diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..4f6a779 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,19 @@ +// A launch configuration that launches the extension inside a new window +// Use IntelliSense to learn about possible attributes. +// Hover to view descriptions of existing attributes. +// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Extension", + "type": "extensionHost", + "request": "launch", + "args": [ + "${workspaceFolder}/testing-util/example.css", + "--extensionDevelopmentPath=${workspaceFolder}" + ], + "preLaunchTask": "prepare-extension-debugging" + } + ] +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..0a5a285 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,11 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "prepare-extension-debugging", + "type": "npm", + "script": "prepare-extension-debugging", + "isBackground": false, + }, + ] +} diff --git a/language-configuration.json b/language-configuration.json new file mode 100644 index 0000000..19d6925 --- /dev/null +++ b/language-configuration.json @@ -0,0 +1,28 @@ +{ + "comments": { + // symbols used for start and end a block comment. + "blockComment": [ "/*", "*/" ] + }, + // symbols used as brackets + "brackets": [ + ["{", "}"], + ["[", "]"], + ["(", ")"] + ], + // symbols that are auto closed when typing + "autoClosingPairs": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["\"", "\""], + ["'", "'"] + ], + // symbols that can be used to surround a selection + "surroundingPairs": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["\"", "\""], + ["'", "'"] + ] +} diff --git a/package-lock.json b/package-lock.json index f4106ba..fb1c16f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,9 @@ "cson": "^8.2.0", "vscode-oniguruma": "^2.0.1", "vscode-textmate": "^9.0.0" + }, + "engines": { + "vscode": "^1.96.0" } }, "node_modules/cson": { diff --git a/package.json b/package.json index c6cae0a..5e7acdc 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,37 @@ "description": "CSS support in VS Code", "version": "0.0.0", "scripts": { + "prepare-extension-debugging": "node ./testing-util/prepare-extension-debugging.mjs ", "test": "node --test ./spec/css-spec.mjs" }, "devDependencies": { "cson": "^8.2.0", "vscode-oniguruma": "^2.0.1", "vscode-textmate": "^9.0.0" + }, + "engines": { + "vscode": "^1.96.0" + }, + "contributes": { + "languages": [ + { + "id": "css", + "aliases": [ + "CSS", + "css" + ], + "extensions": [ + ".css" + ], + "configuration": "./language-configuration.json" + } + ], + "grammars": [ + { + "language": "css", + "scopeName": "source.css", + "path": "./grammars/css.tmLanguage.json" + } + ] } } diff --git a/testing-util/prepare-extension-debugging.mjs b/testing-util/prepare-extension-debugging.mjs new file mode 100644 index 0000000..1d33213 --- /dev/null +++ b/testing-util/prepare-extension-debugging.mjs @@ -0,0 +1,14 @@ +import fs from 'fs'; +import path from 'path'; +import cson from 'cson'; +import { fileURLToPath } from 'url'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +const file = await fs.promises.readFile(path.join(__dirname, '..', 'grammars', 'css.cson')); +await fs.promises.writeFile(path.join(__dirname, '..', 'grammars', 'css.tmLanguage.json'), cson.createJSONString(cson.parse(file.toString()))); + +if (!fs.existsSync(path.join(__dirname, '..', 'testing-util', 'example.css'))) { + await fs.promises.writeFile(path.join(__dirname, '..', 'testing-util', 'example.css'), `.foo {\n\tcolor: lime;\n}\n`); +}