From d37298764fe54de98a4ccf705f1f32bb5ca1f12b Mon Sep 17 00:00:00 2001 From: Mengyan Wu Date: Tue, 7 Nov 2023 16:16:04 -0500 Subject: [PATCH] feat: run prettier --- .eslintrc.json | 50 +++++------ .prettierignore | 3 + .vscode/launch.json | 54 ++++++------ .vscode/settings.json | 22 ++--- .vscode/tasks.json | 69 +++++++-------- CHANGELOG.md | 2 +- README.md | 16 ++-- package-lock.json | 16 ++++ package.json | 3 +- src/extension.ts | 142 +++++++++++++++++-------------- src/influx.ts | 32 ++++--- src/test/runTest.ts | 30 +++---- src/test/suite/extension.test.ts | 16 ++-- src/test/suite/index.ts | 52 +++++------ tsconfig.json | 26 +++--- vsc-extension-quickstart.md | 48 +++++------ webpack.config.js | 34 ++++---- 17 files changed, 318 insertions(+), 297 deletions(-) create mode 100644 .prettierignore diff --git a/.eslintrc.json b/.eslintrc.json index 86c86f3..bb8a001 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,30 +1,24 @@ { - "root": true, - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaVersion": 6, - "sourceType": "module" - }, - "plugins": [ - "@typescript-eslint" + "root": true, + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": 6, + "sourceType": "module" + }, + "plugins": ["@typescript-eslint"], + "rules": { + "@typescript-eslint/naming-convention": [ + "warn", + { + "selector": "import", + "format": ["camelCase", "PascalCase"] + } ], - "rules": { - "@typescript-eslint/naming-convention": [ - "warn", - { - "selector": "import", - "format": [ "camelCase", "PascalCase" ] - } - ], - "@typescript-eslint/semi": "warn", - "curly": "warn", - "eqeqeq": "warn", - "no-throw-literal": "warn", - "semi": "off" - }, - "ignorePatterns": [ - "out", - "dist", - "**/*.d.ts" - ] -} \ No newline at end of file + "@typescript-eslint/semi": "warn", + "curly": "warn", + "eqeqeq": "warn", + "no-throw-literal": "warn", + "semi": "off" + }, + "ignorePatterns": ["out", "dist", "**/*.d.ts"] +} diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..99ffbec --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +out +dist +node_modules \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index d4df9e9..cd54052 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -3,33 +3,29 @@ // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 { - "version": "0.2.0", - "configurations": [ - { - "name": "Run Extension", - "type": "extensionHost", - "request": "launch", - "args": [ - "--extensionDevelopmentPath=${workspaceFolder}" - ], - "outFiles": [ - "${workspaceFolder}/dist/**/*.js" - ], - "preLaunchTask": "${defaultBuildTask}" - }, - { - "name": "Extension Tests", - "type": "extensionHost", - "request": "launch", - "args": [ - "--extensionDevelopmentPath=${workspaceFolder}", - "--extensionTestsPath=${workspaceFolder}/out/test/suite/index" - ], - "outFiles": [ - "${workspaceFolder}/out/**/*.js", - "${workspaceFolder}/dist/**/*.js" - ], - "preLaunchTask": "tasks: watch-tests" - } - ] + "version": "0.2.0", + "configurations": [ + { + "name": "Run Extension", + "type": "extensionHost", + "request": "launch", + "args": ["--extensionDevelopmentPath=${workspaceFolder}"], + "outFiles": ["${workspaceFolder}/dist/**/*.js"], + "preLaunchTask": "${defaultBuildTask}" + }, + { + "name": "Extension Tests", + "type": "extensionHost", + "request": "launch", + "args": [ + "--extensionDevelopmentPath=${workspaceFolder}", + "--extensionTestsPath=${workspaceFolder}/out/test/suite/index" + ], + "outFiles": [ + "${workspaceFolder}/out/**/*.js", + "${workspaceFolder}/dist/**/*.js" + ], + "preLaunchTask": "tasks: watch-tests" + } + ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index 5c5ac48..64ee929 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,13 +1,13 @@ // Place your settings in this file to overwrite default and user settings. { - "files.exclude": { - "out": false, // set this to true to hide the "out" folder with the compiled JS files - "dist": false // set this to true to hide the "dist" folder with the compiled JS files - }, - "search.exclude": { - "out": true, // set this to false to include "out" folder in search results - "dist": true // set this to false to include "dist" folder in search results - }, - // Turn off tsc task auto detection since we have the necessary tasks as npm scripts - "typescript.tsc.autoDetect": "off" -} \ No newline at end of file + "files.exclude": { + "out": false, // set this to true to hide the "out" folder with the compiled JS files + "dist": false // set this to true to hide the "dist" folder with the compiled JS files + }, + "search.exclude": { + "out": true, // set this to false to include "out" folder in search results + "dist": true // set this to false to include "dist" folder in search results + }, + // Turn off tsc task auto detection since we have the necessary tasks as npm scripts + "typescript.tsc.autoDetect": "off" +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json index c2ab68a..9e3300b 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,40 +1,37 @@ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format { - "version": "2.0.0", - "tasks": [ - { - "type": "npm", - "script": "watch", - "problemMatcher": "$ts-webpack-watch", - "isBackground": true, - "presentation": { - "reveal": "never", - "group": "watchers" - }, - "group": { - "kind": "build", - "isDefault": true - } - }, - { - "type": "npm", - "script": "watch-tests", - "problemMatcher": "$tsc-watch", - "isBackground": true, - "presentation": { - "reveal": "never", - "group": "watchers" - }, - "group": "build" - }, - { - "label": "tasks: watch-tests", - "dependsOn": [ - "npm: watch", - "npm: watch-tests" - ], - "problemMatcher": [] - } - ] + "version": "2.0.0", + "tasks": [ + { + "type": "npm", + "script": "watch", + "problemMatcher": "$ts-webpack-watch", + "isBackground": true, + "presentation": { + "reveal": "never", + "group": "watchers" + }, + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "type": "npm", + "script": "watch-tests", + "problemMatcher": "$tsc-watch", + "isBackground": true, + "presentation": { + "reveal": "never", + "group": "watchers" + }, + "group": "build" + }, + { + "label": "tasks: watch-tests", + "dependsOn": ["npm: watch", "npm: watch-tests"], + "problemMatcher": [] + } + ] } diff --git a/CHANGELOG.md b/CHANGELOG.md index bf9347b..82038b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,4 +6,4 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how ## [Unreleased] -- Initial release \ No newline at end of file +- Initial release diff --git a/README.md b/README.md index 4e4a8fb..96faadf 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ For example: This extension contributes the following settings: -* `myExtension.enable`: Enable/disable this extension. -* `myExtension.thing`: Set to `blah` to do something. +- `myExtension.enable`: Enable/disable this extension. +- `myExtension.thing`: Set to `blah` to do something. ## Known Issues @@ -53,19 +53,19 @@ Added features X, Y, and Z. Ensure that you've read through the extensions guidelines and follow the best practices for creating your extension. -* [Extension Guidelines](https://code.visualstudio.com/api/references/extension-guidelines) +- [Extension Guidelines](https://code.visualstudio.com/api/references/extension-guidelines) ## Working with Markdown You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts: -* Split the editor (`Cmd+\` on macOS or `Ctrl+\` on Windows and Linux). -* Toggle preview (`Shift+Cmd+V` on macOS or `Shift+Ctrl+V` on Windows and Linux). -* Press `Ctrl+Space` (Windows, Linux, macOS) to see a list of Markdown snippets. +- Split the editor (`Cmd+\` on macOS or `Ctrl+\` on Windows and Linux). +- Toggle preview (`Shift+Cmd+V` on macOS or `Shift+Ctrl+V` on Windows and Linux). +- Press `Ctrl+Space` (Windows, Linux, macOS) to see a list of Markdown snippets. ## For more information -* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown) -* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/) +- [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown) +- [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/) **Enjoy!** diff --git a/package-lock.json b/package-lock.json index 422abed..f9c5a88 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,7 @@ "eslint": "^8.52.0", "glob": "^10.3.10", "mocha": "^10.2.0", + "prettier": "3.0.3", "ts-loader": "^9.5.0", "typescript": "^5.2.2", "webpack": "^5.89.0", @@ -2705,6 +2706,21 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz", + "integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", diff --git a/package.json b/package.json index 51f9f08..50c6a80 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "eslint": "^8.52.0", "glob": "^10.3.10", "mocha": "^10.2.0", + "prettier": "3.0.3", "ts-loader": "^9.5.0", "typescript": "^5.2.2", "webpack": "^5.89.0", @@ -50,4 +51,4 @@ "dependencies": { "@influxdata/influxdb-client": "^1.33.2" } -} \ No newline at end of file +} diff --git a/src/extension.ts b/src/extension.ts index e4a76e0..c3cee4b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,87 +1,101 @@ -import * as vscode from 'vscode' -import { writeToInfluxDB } from './influx' +import * as vscode from "vscode"; +import { writeToInfluxDB } from "./influx"; -let nextId = 1 -let uri2Id: { [key: string]: number } = {} +let nextId = 1; +let uri2Id: { [key: string]: number } = {}; function getId(uri: string) { - if (!uri2Id.hasOwnProperty(uri)) uri2Id[uri] = nextId++ - return uri2Id[uri] + if (!uri2Id.hasOwnProperty(uri)) uri2Id[uri] = nextId++; + return uri2Id[uri]; } // send entire text document content & update megaphone -function sendDoc(document: vscode.TextDocument, megaphone?: vscode.StatusBarItem) { - if (document.uri.scheme === 'output') { - return; // To avoid logging output panel content - } +function sendDoc( + document: vscode.TextDocument, + megaphone?: vscode.StatusBarItem, +) { + if (document.uri.scheme === "output") { + return; // To avoid logging output panel content + } - const id = getId(document.uri.toString()) - const doc = document.getText() + const id = getId(document.uri.toString()); + const doc = document.getText(); - if (megaphone) { - megaphone.text = `$(megaphone) Document ${id} (${document.fileName}) Open: ${doc.split('\n')[0]}` - } + if (megaphone) { + megaphone.text = `$(megaphone) Document ${id} (${ + document.fileName + }) Open: ${doc.split("\n")[0]}`; + } - writeToInfluxDB('doc', doc, id.toString()) + writeToInfluxDB("doc", doc, id.toString()); } // send text document changes & update megaphone -function sendDocChange(event: vscode.TextDocumentChangeEvent, megaphone: vscode.StatusBarItem) { - if (event.document.uri.scheme === 'output') { - return; // To avoid logging output panel content - } +function sendDocChange( + event: vscode.TextDocumentChangeEvent, + megaphone: vscode.StatusBarItem, +) { + if (event.document.uri.scheme === "output") { + return; // To avoid logging output panel content + } - const id = getId(event.document.uri.toString()) + const id = getId(event.document.uri.toString()); - // For dashboard - // To mirror the content of a document using change events use the following - // approach: - // - start with the same initial content - // - apply the 'textDocument/didChange' notifications in the order you - // receive them. - // - apply the `TextDocumentContentChangeEvent`s in a single notification - // in the order you receive them. - writeToInfluxDB('docChange', JSON.stringify(event.contentChanges), id.toString()) + // For dashboard + // To mirror the content of a document using change events use the following + // approach: + // - start with the same initial content + // - apply the 'textDocument/didChange' notifications in the order you + // receive them. + // - apply the `TextDocumentContentChangeEvent`s in a single notification + // in the order you receive them. + writeToInfluxDB( + "docChange", + JSON.stringify(event.contentChanges), + id.toString(), + ); - // For megaphone - if (event.contentChanges.length === 0) { - megaphone.text = (`$(megaphone) Document ${id} Save`) - } - event.contentChanges.forEach((change) => { - if (change && change.hasOwnProperty('text')) { - const { text, range } = change - if (range.start.isEqual(range.end)) { - megaphone.text = `$(megaphone) Document ${id} Add: ${text}` - } else if (text === '') { - megaphone.text = `$(megaphone) Document ${id} Delete` - } else { - megaphone.text = `$(megaphone) Document ${id} Replace: ${text}` - } - } - }) + // For megaphone + if (event.contentChanges.length === 0) { + megaphone.text = `$(megaphone) Document ${id} Save`; + } + event.contentChanges.forEach((change) => { + if (change && change.hasOwnProperty("text")) { + const { text, range } = change; + if (range.start.isEqual(range.end)) { + megaphone.text = `$(megaphone) Document ${id} Add: ${text}`; + } else if (text === "") { + megaphone.text = `$(megaphone) Document ${id} Delete`; + } else { + megaphone.text = `$(megaphone) Document ${id} Replace: ${text}`; + } + } + }); } export function activate(context: vscode.ExtensionContext) { - console.log('Extension "telemetry" is now active') - console.log(`sessionId: ${vscode.env.sessionId}`) + console.log('Extension "telemetry" is now active'); + console.log(`sessionId: ${vscode.env.sessionId}`); - // create megaphone item on the status bar - let megaphone = vscode.window.createStatusBarItem( - vscode.StatusBarAlignment.Right, - 100 - ) - megaphone.text = `$(megaphone) telemetry extension is activated` - megaphone.show() + // create megaphone item on the status bar + let megaphone = vscode.window.createStatusBarItem( + vscode.StatusBarAlignment.Right, + 100, + ); + megaphone.text = `$(megaphone) telemetry extension is activated`; + megaphone.show(); - // send all text document contents currently known to the editor - vscode.workspace.textDocuments.forEach((doc) => sendDoc(doc)) + // send all text document contents currently known to the editor + vscode.workspace.textDocuments.forEach((doc) => sendDoc(doc)); - // add listeners for document open and document change - context.subscriptions.push( - megaphone, - vscode.workspace.onDidOpenTextDocument((doc) => sendDoc(doc, megaphone)), - vscode.workspace.onDidChangeTextDocument((e: vscode.TextDocumentChangeEvent) => sendDocChange(e, megaphone)) - ) + // add listeners for document open and document change + context.subscriptions.push( + megaphone, + vscode.workspace.onDidOpenTextDocument((doc) => sendDoc(doc, megaphone)), + vscode.workspace.onDidChangeTextDocument( + (e: vscode.TextDocumentChangeEvent) => sendDocChange(e, megaphone), + ), + ); } -export function deactivate() { } \ No newline at end of file +export function deactivate() {} diff --git a/src/influx.ts b/src/influx.ts index dcde7c2..b1fbf0e 100644 --- a/src/influx.ts +++ b/src/influx.ts @@ -1,17 +1,21 @@ -import * as vscode from 'vscode' -import { InfluxDB, Point } from '@influxdata/influxdb-client' -import { org, token, url } from './secrets' +import * as vscode from "vscode"; +import { InfluxDB, Point } from "@influxdata/influxdb-client"; +import { org, token, url } from "./secrets"; -const bucket = 'vs-dev' -const influxDB = new InfluxDB({ url, token }) +const bucket = "vs-dev"; +const influxDB = new InfluxDB({ url, token }); -export async function writeToInfluxDB(eventType: string, eventInfo: string, docId: string) { - const writeApi = influxDB.getWriteApi(org, bucket) - writeApi.useDefaultTags({ from: 'vscode extension' }) - const dataPoint = new Point('telemetry') - .stringField('eventType', eventType) - .stringField('eventInfo', eventInfo) - .tag('sessionId', vscode.env.sessionId) - .tag('docId', docId) - writeApi.writePoint(dataPoint) +export async function writeToInfluxDB( + eventType: string, + eventInfo: string, + docId: string, +) { + const writeApi = influxDB.getWriteApi(org, bucket); + writeApi.useDefaultTags({ from: "vscode extension" }); + const dataPoint = new Point("telemetry") + .stringField("eventType", eventType) + .stringField("eventInfo", eventInfo) + .tag("sessionId", vscode.env.sessionId) + .tag("docId", docId); + writeApi.writePoint(dataPoint); } diff --git a/src/test/runTest.ts b/src/test/runTest.ts index 93a4441..8a6ab0e 100644 --- a/src/test/runTest.ts +++ b/src/test/runTest.ts @@ -1,23 +1,23 @@ -import * as path from 'path'; +import * as path from "path"; -import { runTests } from '@vscode/test-electron'; +import { runTests } from "@vscode/test-electron"; async function main() { - try { - // The folder containing the Extension Manifest package.json - // Passed to `--extensionDevelopmentPath` - const extensionDevelopmentPath = path.resolve(__dirname, '../../'); + try { + // The folder containing the Extension Manifest package.json + // Passed to `--extensionDevelopmentPath` + const extensionDevelopmentPath = path.resolve(__dirname, "../../"); - // The path to test runner - // Passed to --extensionTestsPath - const extensionTestsPath = path.resolve(__dirname, './suite/index'); + // The path to test runner + // Passed to --extensionTestsPath + const extensionTestsPath = path.resolve(__dirname, "./suite/index"); - // Download VS Code, unzip it and run the integration test - await runTests({ extensionDevelopmentPath, extensionTestsPath }); - } catch (err) { - console.error('Failed to run tests', err); - process.exit(1); - } + // Download VS Code, unzip it and run the integration test + await runTests({ extensionDevelopmentPath, extensionTestsPath }); + } catch (err) { + console.error("Failed to run tests", err); + process.exit(1); + } } main(); diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts index 4ca0ab4..2f671d3 100644 --- a/src/test/suite/extension.test.ts +++ b/src/test/suite/extension.test.ts @@ -1,15 +1,15 @@ -import * as assert from 'assert'; +import * as assert from "assert"; // You can import and use all API from the 'vscode' module // as well as import your extension to test it -import * as vscode from 'vscode'; +import * as vscode from "vscode"; // import * as myExtension from '../../extension'; -suite('Extension Test Suite', () => { - vscode.window.showInformationMessage('Start all tests.'); +suite("Extension Test Suite", () => { + vscode.window.showInformationMessage("Start all tests."); - test('Sample test', () => { - assert.strictEqual(-1, [1, 2, 3].indexOf(5)); - assert.strictEqual(-1, [1, 2, 3].indexOf(0)); - }); + test("Sample test", () => { + assert.strictEqual(-1, [1, 2, 3].indexOf(5)); + assert.strictEqual(-1, [1, 2, 3].indexOf(0)); + }); }); diff --git a/src/test/suite/index.ts b/src/test/suite/index.ts index 97ca559..6dd39f7 100644 --- a/src/test/suite/index.ts +++ b/src/test/suite/index.ts @@ -1,32 +1,32 @@ -import * as path from 'path'; -import Mocha from 'mocha'; -import { glob } from 'glob'; +import * as path from "path"; +import Mocha from "mocha"; +import { glob } from "glob"; export async function run(): Promise { - // Create the mocha test - const mocha = new Mocha({ - ui: 'tdd', - color: true - }); + // Create the mocha test + const mocha = new Mocha({ + ui: "tdd", + color: true, + }); - const testsRoot = path.resolve(__dirname, '..'); - const files = await glob('**/**.test.js', { cwd: testsRoot }); + const testsRoot = path.resolve(__dirname, ".."); + const files = await glob("**/**.test.js", { cwd: testsRoot }); - // Add files to the test suite - files.forEach(f => mocha.addFile(path.resolve(testsRoot, f))); + // Add files to the test suite + files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f))); - try { - return new Promise((c, e) => { - // Run the mocha test - mocha.run(failures => { - if (failures > 0) { - e(new Error(`${failures} tests failed.`)); - } else { - c(); - } - }); - }); - } catch (err) { - console.error(err); - } + try { + return new Promise((c, e) => { + // Run the mocha test + mocha.run((failures) => { + if (failures > 0) { + e(new Error(`${failures} tests failed.`)); + } else { + c(); + } + }); + }); + } catch (err) { + console.error(err); + } } diff --git a/tsconfig.json b/tsconfig.json index 8a79f20..bb686be 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,16 +1,14 @@ { - "compilerOptions": { - "module": "Node16", - "target": "ES2022", - "lib": [ - "ES2022" - ], - "sourceMap": true, - "rootDir": "src", - "strict": true /* enable all strict type-checking options */ - /* Additional Checks */ - // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ - // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ - // "noUnusedParameters": true, /* Report errors on unused parameters. */ - } + "compilerOptions": { + "module": "Node16", + "target": "ES2022", + "lib": ["ES2022"], + "sourceMap": true, + "rootDir": "src", + "strict": true /* enable all strict type-checking options */ + /* Additional Checks */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + } } diff --git a/vsc-extension-quickstart.md b/vsc-extension-quickstart.md index b2eb4a4..def139f 100644 --- a/vsc-extension-quickstart.md +++ b/vsc-extension-quickstart.md @@ -2,46 +2,44 @@ ## What's in the folder -* This folder contains all of the files necessary for your extension. -* `package.json` - this is the manifest file in which you declare your extension and command. - * The sample plugin registers a command and defines its title and command name. With this information VS Code can show the command in the command palette. It doesn’t yet need to load the plugin. -* `src/extension.ts` - this is the main file where you will provide the implementation of your command. - * The file exports one function, `activate`, which is called the very first time your extension is activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`. - * We pass the function containing the implementation of the command as the second parameter to `registerCommand`. +- This folder contains all of the files necessary for your extension. +- `package.json` - this is the manifest file in which you declare your extension and command. + - The sample plugin registers a command and defines its title and command name. With this information VS Code can show the command in the command palette. It doesn’t yet need to load the plugin. +- `src/extension.ts` - this is the main file where you will provide the implementation of your command. + - The file exports one function, `activate`, which is called the very first time your extension is activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`. + - We pass the function containing the implementation of the command as the second parameter to `registerCommand`. ## Setup -* install the recommended extensions (amodio.tsl-problem-matcher and dbaeumer.vscode-eslint) - +- install the recommended extensions (amodio.tsl-problem-matcher and dbaeumer.vscode-eslint) ## Get up and running straight away -* Press `F5` to open a new window with your extension loaded. -* Run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`. -* Set breakpoints in your code inside `src/extension.ts` to debug your extension. -* Find output from your extension in the debug console. +- Press `F5` to open a new window with your extension loaded. +- Run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`. +- Set breakpoints in your code inside `src/extension.ts` to debug your extension. +- Find output from your extension in the debug console. ## Make changes -* You can relaunch the extension from the debug toolbar after changing code in `src/extension.ts`. -* You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes. - +- You can relaunch the extension from the debug toolbar after changing code in `src/extension.ts`. +- You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes. ## Explore the API -* You can open the full set of our API when you open the file `node_modules/@types/vscode/index.d.ts`. +- You can open the full set of our API when you open the file `node_modules/@types/vscode/index.d.ts`. ## Run tests -* Open the debug viewlet (`Ctrl+Shift+D` or `Cmd+Shift+D` on Mac) and from the launch configuration dropdown pick `Extension Tests`. -* Press `F5` to run the tests in a new window with your extension loaded. -* See the output of the test result in the debug console. -* Make changes to `src/test/suite/extension.test.ts` or create new test files inside the `test/suite` folder. - * The provided test runner will only consider files matching the name pattern `**.test.ts`. - * You can create folders inside the `test` folder to structure your tests any way you want. +- Open the debug viewlet (`Ctrl+Shift+D` or `Cmd+Shift+D` on Mac) and from the launch configuration dropdown pick `Extension Tests`. +- Press `F5` to run the tests in a new window with your extension loaded. +- See the output of the test result in the debug console. +- Make changes to `src/test/suite/extension.test.ts` or create new test files inside the `test/suite` folder. + - The provided test runner will only consider files matching the name pattern `**.test.ts`. + - You can create folders inside the `test` folder to structure your tests any way you want. ## Go further -* Reduce the extension size and improve the startup time by [bundling your extension](https://code.visualstudio.com/api/working-with-extensions/bundling-extension). -* [Publish your extension](https://code.visualstudio.com/api/working-with-extensions/publishing-extension) on the VS Code extension marketplace. -* Automate builds by setting up [Continuous Integration](https://code.visualstudio.com/api/working-with-extensions/continuous-integration). +- Reduce the extension size and improve the startup time by [bundling your extension](https://code.visualstudio.com/api/working-with-extensions/bundling-extension). +- [Publish your extension](https://code.visualstudio.com/api/working-with-extensions/publishing-extension) on the VS Code extension marketplace. +- Automate builds by setting up [Continuous Integration](https://code.visualstudio.com/api/working-with-extensions/continuous-integration). diff --git a/webpack.config.js b/webpack.config.js index 37d7024..e6ed48c 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,31 +1,31 @@ //@ts-check -'use strict'; +"use strict"; -const path = require('path'); +const path = require("path"); //@ts-check /** @typedef {import('webpack').Configuration} WebpackConfig **/ /** @type WebpackConfig */ const extensionConfig = { - target: 'node', // VS Code extensions run in a Node.js-context πŸ“– -> https://webpack.js.org/configuration/node/ - mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production') + target: "node", // VS Code extensions run in a Node.js-context πŸ“– -> https://webpack.js.org/configuration/node/ + mode: "none", // this leaves the source code as close as possible to the original (when packaging we set this to 'production') - entry: './src/extension.ts', // the entry point of this extension, πŸ“– -> https://webpack.js.org/configuration/entry-context/ + entry: "./src/extension.ts", // the entry point of this extension, πŸ“– -> https://webpack.js.org/configuration/entry-context/ output: { // the bundle is stored in the 'dist' folder (check package.json), πŸ“– -> https://webpack.js.org/configuration/output/ - path: path.resolve(__dirname, 'dist'), - filename: 'extension.js', - libraryTarget: 'commonjs2' + path: path.resolve(__dirname, "dist"), + filename: "extension.js", + libraryTarget: "commonjs2", }, externals: { - vscode: 'commonjs vscode' // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, πŸ“– -> https://webpack.js.org/configuration/externals/ + vscode: "commonjs vscode", // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, πŸ“– -> https://webpack.js.org/configuration/externals/ // modules added here also need to be added in the .vscodeignore file }, resolve: { // support reading TypeScript and JavaScript files, πŸ“– -> https://github.com/TypeStrong/ts-loader - extensions: ['.ts', '.js'] + extensions: [".ts", ".js"], }, module: { rules: [ @@ -34,15 +34,15 @@ const extensionConfig = { exclude: /node_modules/, use: [ { - loader: 'ts-loader' - } - ] - } - ] + loader: "ts-loader", + }, + ], + }, + ], }, - devtool: 'nosources-source-map', + devtool: "nosources-source-map", infrastructureLogging: { level: "log", // enables logging required for problem matchers }, }; -module.exports = [ extensionConfig ]; \ No newline at end of file +module.exports = [extensionConfig];