From 101ffc3a6aaa3c3e25fa543bd2c61f67bc2bd77b Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Thu, 29 Jun 2023 15:59:21 +0100 Subject: [PATCH] chore: Run prettier against project (#24) --- .prettierignore | 3 + .vscode/launch.json | 22 +- README.md | 24 +- language-configuration.json | 44 +-- package.json | 230 +++++++------- snippets/snippets.json | 182 ++++------- syntaxes/noir.tmLanguage.json | 580 ++++++++++++++++++---------------- tsconfig.json | 28 +- 8 files changed, 557 insertions(+), 556 deletions(-) create mode 100644 .prettierignore diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..c5fcba3 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +CHANGELOG.md +out/ +package-lock.json diff --git a/.vscode/launch.json b/.vscode/launch.json index 0e191b5..4058e69 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -3,15 +3,13 @@ // 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": [ - "--extensionDevelopmentPath=${workspaceFolder}" - ] - } - ] -} \ No newline at end of file + "version": "0.2.0", + "configurations": [ + { + "name": "Extension", + "type": "extensionHost", + "request": "launch", + "args": ["--extensionDevelopmentPath=${workspaceFolder}"] + } + ] +} diff --git a/README.md b/README.md index d7048cb..9dd4c34 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,9 @@ Visual Studio Code extension for working with the [Noir programming language](ht This extension helps developers write, understand, and improve Noir code by providing: -* Syntax highlighting -* Compile errors and warnings on file save -* Useful snippets for common code patterns +- Syntax highlighting +- Compile errors and warnings on file save +- Useful snippets for common code patterns ## Requirements @@ -18,10 +18,10 @@ If you can't put `nargo` in your `PATH`, you can set an absolute path in the `Na ## Settings -* __Noir: Enable LSP__ _(noir.enableLSP)_ - If checked, the extension will launch the Language Server via `nargo lsp` and communicate with it. -* __Noir: Nargo Flags__ _(noir.nargoFlags)_ - Additional flags may be specified if you require them to be added when the extension calls `nargo lsp`. -* __Noir: Nargo Path__ _(noir.nargoPath)_ - An absolute path to a Nargo binary with the `lsp` command. This may be useful if Nargo is not within the `PATH` of your editor. -* __Noir > Trace: Server__ _(noir.trace.server)_ - Setting this to `"messages"` or `"verbose"` will log LSP messages between the Client and Server. Useful for debugging. +- **Noir: Enable LSP** _(noir.enableLSP)_ - If checked, the extension will launch the Language Server via `nargo lsp` and communicate with it. +- **Noir: Nargo Flags** _(noir.nargoFlags)_ - Additional flags may be specified if you require them to be added when the extension calls `nargo lsp`. +- **Noir: Nargo Path** _(noir.nargoPath)_ - An absolute path to a Nargo binary with the `lsp` command. This may be useful if Nargo is not within the `PATH` of your editor. +- **Noir > Trace: Server** _(noir.trace.server)_ - Setting this to `"messages"` or `"verbose"` will log LSP messages between the Client and Server. Useful for debugging. ## Changelog @@ -31,8 +31,8 @@ You can find a full list of changes at https://github.com/noir-lang/vscode-noir/ The project provides a few useful commands via npm scripts: -* `npm run package` - Builds the project and packages it into a `.vsix` file which can be manually installed for testing. -* `npm run esbuild` - Builds the project with esbuild to output `out/extension.js` and `out/extension.js.map`. -* `npm run test-compile` - Check types with TypeScript. Useful since esbuild doesn't typecheck. -* `npm run format` - Formats all the code in the repository. -* `npm run check-format` - Checks the formatting in the repository. +- `npm run package` - Builds the project and packages it into a `.vsix` file which can be manually installed for testing. +- `npm run esbuild` - Builds the project with esbuild to output `out/extension.js` and `out/extension.js.map`. +- `npm run test-compile` - Check types with TypeScript. Useful since esbuild doesn't typecheck. +- `npm run format` - Formats all the code in the repository. +- `npm run check-format` - Checks the formatting in the repository. diff --git a/language-configuration.json b/language-configuration.json index 2d36dc2..9ef0db8 100644 --- a/language-configuration.json +++ b/language-configuration.json @@ -1,23 +1,23 @@ { - "comments": { - "lineComment": "//", - "blockComment": [ "/*", "*/" ] - }, - "brackets": [ - ["{", "}"], - ["[", "]"], - ["(", ")"] - ], - "autoClosingPairs": [ - ["{", "}"], - ["[", "]"], - ["(", ")"], - ["\"", "\""] - ], - "surroundingPairs": [ - ["{", "}"], - ["[", "]"], - ["(", ")"], - ["\"", "\""] - ] -} \ No newline at end of file + "comments": { + "lineComment": "//", + "blockComment": ["/*", "*/"] + }, + "brackets": [ + ["{", "}"], + ["[", "]"], + ["(", ")"] + ], + "autoClosingPairs": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["\"", "\""] + ], + "surroundingPairs": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["\"", "\""] + ] +} diff --git a/package.json b/package.json index 0f4bdbd..9944d88 100644 --- a/package.json +++ b/package.json @@ -1,123 +1,123 @@ { - "name": "vscode-noir", - "displayName": "Noir Language Support", - "description": "Noir support for Visual Studio Code", - "version": "0.0.3", - "publisher": "noir-lang", - "keywords": [ - "noir", - "noir-lang" + "name": "vscode-noir", + "displayName": "Noir Language Support", + "description": "Noir support for Visual Studio Code", + "version": "0.0.3", + "publisher": "noir-lang", + "keywords": [ + "noir", + "noir-lang" + ], + "icon": "noir.png", + "engines": { + "vscode": "^1.67.0" + }, + "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/noir-lang/vscode-noir" + }, + "bugs": { + "url": "https://github.com/noir-lang/vscode-noir/issues" + }, + "categories": [ + "Programming Languages" + ], + "activationEvents": [ + "onLanguage:noir" + ], + "main": "./out/extension", + "contributes": { + "commands": [ + { + "command": "noir.restart", + "title": "Noir: Restart Language Server" + } ], - "icon": "noir.png", - "engines": { - "vscode": "^1.67.0" - }, - "license": "Apache-2.0", - "repository": { - "type": "git", - "url": "https://github.com/noir-lang/vscode-noir" - }, - "bugs": { - "url": "https://github.com/noir-lang/vscode-noir/issues" - }, - "categories": [ - "Programming Languages" + "snippets": [ + { + "language": "noir", + "path": "./snippets/snippets.json" + } ], - "activationEvents": [ - "onLanguage:noir" - ], - "main": "./out/extension", - "contributes": { - "commands": [ - { - "command": "noir.restart", - "title": "Noir: Restart Language Server" - } - ], - "snippets": [ - { - "language": "noir", - "path": "./snippets/snippets.json" - } - ], - "languages": [ - { - "id": "noir", - "aliases": [ - "Noir", - "noir" - ], - "extensions": [ - ".nr" - ], - "configuration": "./language-configuration.json" - } + "languages": [ + { + "id": "noir", + "aliases": [ + "Noir", + "noir" ], - "grammars": [ - { - "language": "noir", - "scopeName": "source.nr", - "path": "./syntaxes/noir.tmLanguage.json" - } + "extensions": [ + ".nr" ], - "configuration": { - "type": "object", - "title": "Noir Language Server configuration", - "properties": { - "noir.nargoFlags": { - "scope": "resource", - "type": "string", - "description": "Space-separated list of flags to pass to the nargo CLI" - }, - "noir.nargoPath": { - "scope": "resource", - "type": "string", - "description": "Absolute path to the nargo CLI (detected in PATH if not specified)" - }, - "noir.enableLSP": { - "scope": "resource", - "type": "boolean", - "default": true, - "description": "Enable the language server" - }, - "noir.trace.server": { - "scope": "resource", - "type": "string", - "enum": [ - "off", - "messages", - "verbose" - ], - "default": "off", - "description": "Traces the communication between VS Code and the language server." - } - } + "configuration": "./language-configuration.json" + } + ], + "grammars": [ + { + "language": "noir", + "scopeName": "source.nr", + "path": "./syntaxes/noir.tmLanguage.json" + } + ], + "configuration": { + "type": "object", + "title": "Noir Language Server configuration", + "properties": { + "noir.nargoFlags": { + "scope": "resource", + "type": "string", + "description": "Space-separated list of flags to pass to the nargo CLI" + }, + "noir.nargoPath": { + "scope": "resource", + "type": "string", + "description": "Absolute path to the nargo CLI (detected in PATH if not specified)" + }, + "noir.enableLSP": { + "scope": "resource", + "type": "boolean", + "default": true, + "description": "Enable the language server" + }, + "noir.trace.server": { + "scope": "resource", + "type": "string", + "enum": [ + "off", + "messages", + "verbose" + ], + "default": "off", + "description": "Traces the communication between VS Code and the language server." } - }, - "scripts": { - "vscode:prepublish": "npm run esbuild-base -- --minify", - "esbuild-base": "esbuild ./src/extension.ts --bundle --outfile=out/extension.js --external:vscode --format=cjs --platform=node", - "esbuild": "npm run esbuild-base -- --sourcemap", - "esbuild-watch": "npm run esbuild-base -- --sourcemap --watch", - "package": "vsce package", - "test-compile": "tsc -p ./", - "format": "prettier --write .", - "check-format": "prettier --check .", - "deploy": "vsce publish" - }, - "dependencies": { - "vscode-languageclient": "^8.0.3", - "which": "^3.0.1" - }, - "devDependencies": { - "@types/node": "^12.12.0", - "@types/vscode": "1.67.0", - "@types/which": "^3.0.0", - "@typescript-eslint/parser": "^5.59.9", - "esbuild": "^0.17.19", - "eslint": "^8.42.0", - "prettier": "^2.8.8", - "typescript": "^5.1.3", - "vsce": "^2.15.0" + } } + }, + "scripts": { + "vscode:prepublish": "npm run esbuild-base -- --minify", + "esbuild-base": "esbuild ./src/extension.ts --bundle --outfile=out/extension.js --external:vscode --format=cjs --platform=node", + "esbuild": "npm run esbuild-base -- --sourcemap", + "esbuild-watch": "npm run esbuild-base -- --sourcemap --watch", + "package": "vsce package", + "test-compile": "tsc -p ./", + "format": "prettier --write .", + "check-format": "prettier --check .", + "deploy": "vsce publish" + }, + "dependencies": { + "vscode-languageclient": "^8.0.3", + "which": "^3.0.1" + }, + "devDependencies": { + "@types/node": "^12.12.0", + "@types/vscode": "1.67.0", + "@types/which": "^3.0.0", + "@typescript-eslint/parser": "^5.59.9", + "esbuild": "^0.17.19", + "eslint": "^8.42.0", + "prettier": "^2.8.8", + "typescript": "^5.1.3", + "vsce": "^2.15.0" + } } diff --git a/snippets/snippets.json b/snippets/snippets.json index 5325993..98e6280 100644 --- a/snippets/snippets.json +++ b/snippets/snippets.json @@ -1,113 +1,71 @@ { - "Module": { - "prefix": "mod", - "body": [ - "mod ${1:name};" - ], - "description": "Declare a module." - }, - "Use Module": { - "prefix": "use", - "body": [ - "use ${1:name};" - ], - "description": "Use a module." - }, - "Function": { - "prefix": "fn", - "body": [ - "fn ${1:name} () {", - "\t$0", - "}" - ], - "description": "Declare a function." - }, - "Function Main": { - "prefix": "fnmain", - "body": [ - "fn main () {", - "\t$0", - "}" - ], - "description": "Declare a function." - }, - "Struct": { - "prefix": "struct", - "body": [ - "struct ${1:name} {", - "\t$0", - "}" - ], - "description": "Declare a struct." - }, - "Let": { - "prefix": "let", - "body": [ - "let ${1:variable} = $0" - ], - "description": "Declare a variable." - }, - "Let = For": { - "prefix": "letfor", - "body": [ - "let ${1:array} = for ${2:start} .. ${3:end} {", - "\t$0", - "}" - ], - "description": "Declare an array defined by a for-loop." - }, - "Let = For .. In": { - "prefix": "letforin", - "body": [ - "let ${1:array} = for ${2:index} in ${3:start} .. ${4:end} {", - "\t$0", - "}" - ], - "description": "Declare an array defined by a for-in-loop." - }, - "For": { - "prefix": "for", - "body": [ - "for ${2:start} .. ${3:end} {", - "\t$0", - "}" - ], - "description": "Declare an array defined by a for-loop." - }, - "For .. In": { - "prefix": "forin", - "body": [ - "for ${2:index} in ${3:start} .. ${4:end} {", - "\t$0", - "}" - ], - "description": "Declare an array defined by a for-in-loop." - }, - "If-Statement": { - "prefix": "if", - "body": [ - "if ${1:condition} {", - "\t$0", - "}" - ], - "description": "Declare an if-statement" - }, - "Elseif-Statement": { - "prefix": "elseif", - "body": [ - "else if ${1:condition} {", - "\t$0", - "}" - ], - "description": "Declare a else-if-statement" - }, - "Else-Statement": { - "prefix": "else", - "body": [ - "else {", - "\t$0", - "}" - ], - "description": "Declare a else-statement" - } -} \ No newline at end of file + "Module": { + "prefix": "mod", + "body": ["mod ${1:name};"], + "description": "Declare a module." + }, + "Use Module": { + "prefix": "use", + "body": ["use ${1:name};"], + "description": "Use a module." + }, + "Function": { + "prefix": "fn", + "body": ["fn ${1:name} () {", "\t$0", "}"], + "description": "Declare a function." + }, + "Function Main": { + "prefix": "fnmain", + "body": ["fn main () {", "\t$0", "}"], + "description": "Declare a function." + }, + "Struct": { + "prefix": "struct", + "body": ["struct ${1:name} {", "\t$0", "}"], + "description": "Declare a struct." + }, + "Let": { + "prefix": "let", + "body": ["let ${1:variable} = $0"], + "description": "Declare a variable." + }, + "Let = For": { + "prefix": "letfor", + "body": ["let ${1:array} = for ${2:start} .. ${3:end} {", "\t$0", "}"], + "description": "Declare an array defined by a for-loop." + }, + "Let = For .. In": { + "prefix": "letforin", + "body": [ + "let ${1:array} = for ${2:index} in ${3:start} .. ${4:end} {", + "\t$0", + "}" + ], + "description": "Declare an array defined by a for-in-loop." + }, + "For": { + "prefix": "for", + "body": ["for ${2:start} .. ${3:end} {", "\t$0", "}"], + "description": "Declare an array defined by a for-loop." + }, + "For .. In": { + "prefix": "forin", + "body": ["for ${2:index} in ${3:start} .. ${4:end} {", "\t$0", "}"], + "description": "Declare an array defined by a for-in-loop." + }, + "If-Statement": { + "prefix": "if", + "body": ["if ${1:condition} {", "\t$0", "}"], + "description": "Declare an if-statement" + }, + "Elseif-Statement": { + "prefix": "elseif", + "body": ["else if ${1:condition} {", "\t$0", "}"], + "description": "Declare a else-if-statement" + }, + "Else-Statement": { + "prefix": "else", + "body": ["else {", "\t$0", "}"], + "description": "Declare a else-statement" + } +} diff --git a/syntaxes/noir.tmLanguage.json b/syntaxes/noir.tmLanguage.json index e94df44..f109901 100644 --- a/syntaxes/noir.tmLanguage.json +++ b/syntaxes/noir.tmLanguage.json @@ -1,268 +1,316 @@ { - "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", - "name": "The Noir Programming Language", - "patterns": [{ - "include": "#code" - }], - "repository": { - "code": { - "patterns": [{ - "include": "#comments" - }, - { - "include": "#strings" - }, - { - "include": "#numeric" - }, - { - "include": "#syntax" - }, - { - "include": "#attribute" - }, - { - "include": "#keywords" - }, - { - "include": "#input" - } - ] - }, - "comments": { - "patterns": [{ - "begin": "\\/\\*", - "end": "\\*\\/", - "name": "comment.block.nr", - "patterns": [{ - "include": "#comments" - }] - }, { - "match": "\\/\\/.*\n", - "name": "comment.line.double-slash.nr" - }] - }, - "strings": { - "name": "string.quoted.double.nr", - "match": "\"(.*?)(\n|(?)\\s*([a-zA-Z_][a-zA-Z0-9_]*)", - "captures": { - "1": { - "name": "keyword.control.nr" - }, - "2": { - "name": "support.type.nr" - } - } - } - ] - }, - "attribute": { - "begin": "#\\[", - "end": "\\]", - "patterns": [{ - "begin": "[a-zA-Z_][a-zA-Z0-9_]\\s*\\(", - "end": "\\)" - }, { - "match": "[a-zA-Z_][a-zA-Z0-9_]" - }] - }, - "keywords": { - "patterns": [{ - "name": "keyword.control.nr", - "match": "\\b(fn|mod|use|struct|if|else|for|constrain)\\b" - }, { - "name": "keyword.nr", - "match": "\\b(global|comptime|pub|in|as|let|true|false)\\b" - }] - }, - "input": { - "patterns": [{ - "name": "support.type.nr", - "match": "\\b((u|i)\\d+|str|bool|Field|Witness)\\b" - }, { - "name": "support.type.nr", - "match": "\\b(_*[A-Z][a-zA-Z0-9_]*|[a-zA-Z_][a-zA-Z0-9_]*::)\\b" - }, { - "begin": "\\b([a-z_][a-zA-Z0-9_]*)\\s*\\(", - "end": "\\)", - "beginCaptures": { - "1": { - "name": "support.function.nr" - } - }, - "patterns": [{ - "include": "#code" - }] - }, { - "name": "variable.nr", - "match": "\\b[a-z_][a-zA-Z0-9_]*\\b" - }] - }, - "--struct-content": { - "patterns": [{ - "begin": "[a-zA-Z_][a-zA-Z0-9_]*", - "end": "([a-zA-Z_][a-zA-Z0-9_]*)|,", - "beginCaptures": { - "0": { - "name": "support.type.property-name.nr" - } - }, - "endCaptures": { - "1": { - "name": "support.type.nr" - } - }, - "patterns": [{ - "include": "#comments" - }] - }, { - "begin": "<", - "end": ">", - "patterns": [{ - "include": "#--struct-types" - }] - }, { - "include": "#comments" - }] - }, - "--struct-types": { - "patterns": [{ - "match": "[a-zA-Z_][a-zA-Z0-9_]*", - "name": "support.type.nr" - }, { - "begin": "<", - "end": ">", - "patterns": [{ - "include": "#--struct-types" - }] - }, { - "include": "#comments" - }] - } - }, - "scopeName": "source.nr" + "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", + "name": "The Noir Programming Language", + "patterns": [ + { + "include": "#code" + } + ], + "repository": { + "code": { + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#strings" + }, + { + "include": "#numeric" + }, + { + "include": "#syntax" + }, + { + "include": "#attribute" + }, + { + "include": "#keywords" + }, + { + "include": "#input" + } + ] + }, + "comments": { + "patterns": [ + { + "begin": "\\/\\*", + "end": "\\*\\/", + "name": "comment.block.nr", + "patterns": [ + { + "include": "#comments" + } + ] + }, + { + "match": "\\/\\/.*\n", + "name": "comment.line.double-slash.nr" + } + ] + }, + "strings": { + "name": "string.quoted.double.nr", + "match": "\"(.*?)(\n|(?)\\s*([a-zA-Z_][a-zA-Z0-9_]*)", + "captures": { + "1": { + "name": "keyword.control.nr" + }, + "2": { + "name": "support.type.nr" + } + } + } + ] + }, + "attribute": { + "begin": "#\\[", + "end": "\\]", + "patterns": [ + { + "begin": "[a-zA-Z_][a-zA-Z0-9_]\\s*\\(", + "end": "\\)" + }, + { + "match": "[a-zA-Z_][a-zA-Z0-9_]" + } + ] + }, + "keywords": { + "patterns": [ + { + "name": "keyword.control.nr", + "match": "\\b(fn|mod|use|struct|if|else|for|constrain)\\b" + }, + { + "name": "keyword.nr", + "match": "\\b(global|comptime|pub|in|as|let|true|false)\\b" + } + ] + }, + "input": { + "patterns": [ + { + "name": "support.type.nr", + "match": "\\b((u|i)\\d+|str|bool|Field|Witness)\\b" + }, + { + "name": "support.type.nr", + "match": "\\b(_*[A-Z][a-zA-Z0-9_]*|[a-zA-Z_][a-zA-Z0-9_]*::)\\b" + }, + { + "begin": "\\b([a-z_][a-zA-Z0-9_]*)\\s*\\(", + "end": "\\)", + "beginCaptures": { + "1": { + "name": "support.function.nr" + } + }, + "patterns": [ + { + "include": "#code" + } + ] + }, + { + "name": "variable.nr", + "match": "\\b[a-z_][a-zA-Z0-9_]*\\b" + } + ] + }, + "--struct-content": { + "patterns": [ + { + "begin": "[a-zA-Z_][a-zA-Z0-9_]*", + "end": "([a-zA-Z_][a-zA-Z0-9_]*)|,", + "beginCaptures": { + "0": { + "name": "support.type.property-name.nr" + } + }, + "endCaptures": { + "1": { + "name": "support.type.nr" + } + }, + "patterns": [ + { + "include": "#comments" + } + ] + }, + { + "begin": "<", + "end": ">", + "patterns": [ + { + "include": "#--struct-types" + } + ] + }, + { + "include": "#comments" + } + ] + }, + "--struct-types": { + "patterns": [ + { + "match": "[a-zA-Z_][a-zA-Z0-9_]*", + "name": "support.type.nr" + }, + { + "begin": "<", + "end": ">", + "patterns": [ + { + "include": "#--struct-types" + } + ] + }, + { + "include": "#comments" + } + ] + } + }, + "scopeName": "source.nr" } diff --git a/tsconfig.json b/tsconfig.json index 20fa4b3..c8b1849 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,19 +1,13 @@ { - "compilerOptions": { - "module": "commonjs", - "target": "es2022", - "lib": [ - "ES2022" - ], - "outDir": "out", - "rootDir": "src", - "sourceMap": true, - "esModuleInterop": true - }, - "include": [ - "src/*" - ], - "exclude": [ - "node_modules" - ] + "compilerOptions": { + "module": "commonjs", + "target": "es2022", + "lib": ["ES2022"], + "outDir": "out", + "rootDir": "src", + "sourceMap": true, + "esModuleInterop": true + }, + "include": ["src/*"], + "exclude": ["node_modules"] }