Skip to content

Commit

Permalink
feat: add snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
lvjiaxuan committed Aug 24, 2022
1 parent 4d987ef commit 48fba0b
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"preLaunchTask": "${defaultBuildTask}",
"preLaunchTask": "${defaultBuildTask}"
}
]
}
11 changes: 0 additions & 11 deletions .vscode/settings.json

This file was deleted.

2 changes: 1 addition & 1 deletion Guides.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

# [Background / watching tasks](https://code.visualstudio.com/docs/editor/tasks%5C#_background-watching-tasks)

[tasks.json](./.vscode/tasks.json)
[tasks.json](./.vscode/tasks.json)
22 changes: 21 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,27 @@
"title": "Hello World"
}
],
"snippets": []
"snippets": [
{
"language": "javascript",
"path": "./snippets/snippets.json"
},
{
"language": "javascriptreact",
"path": "./snippets/snippets.json"
},
{
"language": "typescript",
"path": "./snippets/snippets.json"
},
{
"language": "typescriptreact",
"path": "./snippets/snippets.json"
}
],
"menus": {
"editor/context": []
}
},
"scripts": {
"compile": "tsup src/extension.ts --external=vscode --format=cjs --clean",
Expand Down
15 changes: 15 additions & 0 deletions snippets/snippets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"eslint-disable": {
"prefix": "eslint-disable",
"body": [
"/* eslint-disable ${1|INSERT_RULES|} */",
"$0/* eslint-enable ${1} */"
],
"description": "ESLint disable wrapper"
},
"eslint-disable-next-line": {
"prefix": "eslint-disable-next-line",
"body": ["// eslint-disable-next-line ${1|INSERT_RULES|}"],
"description": "ESLint disable next line"
}
}
24 changes: 6 additions & 18 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode'
import vscode from 'vscode'


// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {

// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "eslint-disable" is now active!')

// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
const disposable = vscode.commands.registerCommand('eslint-disable.helloWorld', () => {
// The code you place here will be executed every time your command is executed
// Display a message box to the user
void vscode.window.showInformationMessage('Hello World from eslint-disable!')
})

context.subscriptions.push(disposable)
context.subscriptions.push(helloWorld())
}

// this method is called when your extension is deactivated
export function deactivate() {
// ...
}

/**
* 1. 读 eslint config 配置,获取所有rules config
*/
const helloWorld = () =>
vscode.commands.registerCommand('eslint-disable.helloWorld', () =>
vscode.window.showInformationMessage('Hello World from eslint-disable!!!'))

0 comments on commit 48fba0b

Please sign in to comment.