vscode插件开发
·
初始化项目
npm install --global yo generator-code
yo code
项目配置文件
launch.json
// A launch configuration that compiles the extension and then opens it inside a new window
{
"version": "0.2.0",
"configurations": [
{
"type": "extensionHost", // "extensionHost"为调试扩展, "node" "go"
"request": "launch", // "launch" "attach"
"name": "Launch Client",
"runtimeExecutable": "${execPath}", // 指定调试时要启动的可执行文件, ${execPath}指向vscode
"args": ["--extensionDevelopmentPath=${workspaceRoot}"], // 传递给上面的参数
"outFiles": [
"${workspaceRoot}/client/out/**/*.js",
"${workspaceRoot}/server/out/**/*.js"
],
"autoAttachChildProcesses": true,
"preLaunchTask": { // 运行后才launch
"type": "npm",
"script": "compile"
}
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "compile",
"group": "build", # "build" "test"
"presentation": {
"panel": "dedicated", # "shared"共享terminal "dedicated"一个task一个terminal "new"每次运行新建terminal
"reveal": "never" # "always"(default) "silent" "never"
},
"problemMatcher": [
"$tsc" # vscode内置tsc
]
},
{
"type": "npm",
"script": "watch",
"isBackground": true,
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"panel": "dedicated",
"reveal": "never"
},
"problemMatcher": [
"$tsc-watch" # vscode内置
]
}
]
}
vscode提供的api
https://code.visualstudio.com/api/references/vscode-api
import { window } from "vscode";
window.showErrorMessage("string"); // 右下角显示窗口
import { commands } from "vscode";
executeCommand<T>(command: string, ...rest: any[]): Thenable<T>
getCommands(filterInternal?: boolean): Thenable<string[]>
registerCommand(command: string, callback: (args: any[]) => any, thisArg?: any): Disposable
registerTextEditorCommand(command: string, callback: (textEditor: TextEditor, edit: TextEditorEdit, args: any[]) => void, thisArg?: any): Disposable
import { extensions } from "vscode";
all: readonly Extension<any>[]
getExtension<T>(extensionId: string): Extension<T> | undefined
import { workspace } from "vscode";
workspace.createFileSystemWatcher("**/.clientrc"); //监听文件的操作
import { languages } from "vscode";
lsp
Language Server Protocol
api
notification
不需要response
'workspace/didChangeWatchedFiles'
'textDocument/didChange'
'textDocument/didClose'
request
需要response
'textDocument/diagnostic'
[Trace - 2:38:41 PM] Sending request 'initialize - (0)'.
Params: {
"processId": 7320,
"clientInfo": {
"name": "Visual Studio Code",
"version": "1.123.0"
},
"locale": "en",
"rootPath": "c:\\Users\\19141\\Desktop\\batis",
"rootUri": "file:///c%3A/Users/19141/Desktop/batis",
"capabilities": {
"workspace": {
"applyEdit": true,
"workspaceEdit": {
"documentChanges": true,
"resourceOperations": [
"create",
"rename",
"delete"
],
"failureHandling": "textOnlyTransactional",
"normalizesLineEndings": true,
"changeAnnotationSupport": {
"groupsOnLabel": true
}
},
"configuration": true,
"didChangeWatchedFiles": {
"dynamicRegistration": true,
"relativePatternSupport": true
},
"symbol": {
"dynamicRegistration": true,
"symbolKind": {
"valueSet": [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26
]
},
"tagSupport": {
"valueSet": [
1
]
},
"resolveSupport": {
"properties": [
"location.range"
]
}
},
"codeLens": {
"refreshSupport": true
},
"executeCommand": {
"dynamicRegistration": true
},
"didChangeConfiguration": {
"dynamicRegistration": true
},
"workspaceFolders": true,
"foldingRange": {
"refreshSupport": true
},
"semanticTokens": {
"refreshSupport": true
},
"fileOperations": {
"dynamicRegistration": true,
"didCreate": true,
"didRename": true,
"didDelete": true,
"willCreate": true,
"willRename": true,
"willDelete": true
},
"inlineValue": {
"refreshSupport": true
},
"inlayHint": {
"refreshSupport": true
},
"diagnostics": {
"refreshSupport": true
}
},
"textDocument": {
"publishDiagnostics": {
"relatedInformation": true,
"versionSupport": false,
"tagSupport": {
"valueSet": [
1,
2
]
},
"codeDescriptionSupport": true,
"dataSupport": true
},
"synchronization": {
"dynamicRegistration": true,
"willSave": true,
"willSaveWaitUntil": true,
"didSave": true
},
"completion": {
"dynamicRegistration": true,
"contextSupport": true,
"completionItem": {
"snippetSupport": true,
"commitCharactersSupport": true,
"documentationFormat": [
"markdown",
"plaintext"
],
"deprecatedSupport": true,
"preselectSupport": true,
"tagSupport": {
"valueSet": [
1
]
},
"insertReplaceSupport": true,
"resolveSupport": {
"properties": [
"documentation",
"detail",
"additionalTextEdits"
]
},
"insertTextModeSupport": {
"valueSet": [
1,
2
]
},
"labelDetailsSupport": true
},
"insertTextMode": 2,
"completionItemKind": {
"valueSet": [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25
]
},
"completionList": {
"itemDefaults": [
"commitCharacters",
"editRange",
"insertTextFormat",
"insertTextMode",
"data"
]
}
},
"hover": {
"dynamicRegistration": true,
"contentFormat": [
"markdown",
"plaintext"
]
},
"signatureHelp": {
"dynamicRegistration": true,
"signatureInformation": {
"documentationFormat": [
"markdown",
"plaintext"
],
"parameterInformation": {
"labelOffsetSupport": true
},
"activeParameterSupport": true
},
"contextSupport": true
},
"definition": {
"dynamicRegistration": true,
"linkSupport": true
},
"references": {
"dynamicRegistration": true
},
"documentHighlight": {
"dynamicRegistration": true
},
"documentSymbol": {
"dynamicRegistration": true,
"symbolKind": {
"valueSet": [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26
]
},
"hierarchicalDocumentSymbolSupport": true,
"tagSupport": {
"valueSet": [
1
]
},
"labelSupport": true
},
"codeAction": {
"dynamicRegistration": true,
"isPreferredSupport": true,
"disabledSupport": true,
"dataSupport": true,
"resolveSupport": {
"properties": [
"edit"
]
},
"codeActionLiteralSupport": {
"codeActionKind": {
"valueSet": [
"",
"quickfix",
"refactor",
"refactor.extract",
"refactor.inline",
"refactor.rewrite",
"source",
"source.organizeImports"
]
}
},
"honorsChangeAnnotations": true
},
"codeLens": {
"dynamicRegistration": true
},
"formatting": {
"dynamicRegistration": true
},
"rangeFormatting": {
"dynamicRegistration": true,
"rangesSupport": true
},
"onTypeFormatting": {
"dynamicRegistration": true
},
"rename": {
"dynamicRegistration": true,
"prepareSupport": true,
"prepareSupportDefaultBehavior": 1,
"honorsChangeAnnotations": true
},
"documentLink": {
"dynamicRegistration": true,
"tooltipSupport": true
},
"typeDefinition": {
"dynamicRegistration": true,
"linkSupport": true
},
"implementation": {
"dynamicRegistration": true,
"linkSupport": true
},
"colorProvider": {
"dynamicRegistration": true
},
"foldingRange": {
"dynamicRegistration": true,
"rangeLimit": 5000,
"lineFoldingOnly": true,
"foldingRangeKind": {
"valueSet": [
"comment",
"imports",
"region"
]
},
"foldingRange": {
"collapsedText": false
}
},
"declaration": {
"dynamicRegistration": true,
"linkSupport": true
},
"selectionRange": {
"dynamicRegistration": true
},
"callHierarchy": {
"dynamicRegistration": true
},
"semanticTokens": {
"dynamicRegistration": true,
"tokenTypes": [
"namespace",
"type",
"class",
"enum",
"interface",
"struct",
"typeParameter",
"parameter",
"variable",
"property",
"enumMember",
"event",
"function",
"method",
"macro",
"keyword",
"modifier",
"comment",
"string",
"number",
"regexp",
"operator",
"decorator"
],
"tokenModifiers": [
"declaration",
"definition",
"readonly",
"static",
"deprecated",
"abstract",
"async",
"modification",
"documentation",
"defaultLibrary"
],
"formats": [
"relative"
],
"requests": {
"range": true,
"full": {
"delta": true
}
},
"multilineTokenSupport": false,
"overlappingTokenSupport": false,
"serverCancelSupport": true,
"augmentsSyntaxTokens": true
},
"linkedEditingRange": {
"dynamicRegistration": true
},
"typeHierarchy": {
"dynamicRegistration": true
},
"inlineValue": {
"dynamicRegistration": true
},
"inlayHint": {
"dynamicRegistration": true,
"resolveSupport": {
"properties": [
"tooltip",
"textEdits",
"label.tooltip",
"label.location",
"label.command"
]
}
},
"diagnostic": {
"dynamicRegistration": true,
"relatedDocumentSupport": false
}
},
"window": {
"showMessage": {
"messageActionItem": {
"additionalPropertiesSupport": true
}
},
"showDocument": {
"support": true
},
"workDoneProgress": true
},
"general": {
"staleRequestSupport": {
"cancel": true,
"retryOnContentModified": [
"textDocument/semanticTokens/full",
"textDocument/semanticTokens/range",
"textDocument/semanticTokens/full/delta"
]
},
"regularExpressions": {
"engine": "ECMAScript",
"version": "ES2020"
},
"markdown": {
"parser": "marked",
"version": "1.1.0"
},
"positionEncodings": [
"utf-16"
]
},
"notebookDocument": {
"synchronization": {
"dynamicRegistration": true,
"executionSummarySupport": true
}
}
},
"trace": "verbose",
"workspaceFolders": [
{
"uri": "file:///c%3A/Users/19141/Desktop/batis",
"name": "batis"
}
]
}
didChange
[Trace - 4:21:11 PM] Sending notification 'textDocument/didChange'.
Params: {
"textDocument": {
"uri": "file:///c%3A/Users/19141/Desktop/batis/src/main/java/com/example/batis/EntityDTO.java",
"version": 2
},
"contentChanges": [
{
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 0,
"character": 0
}
},
"rangeLength": 0,
"text": "package com.example.batis;\r\n\r\npublic class EntityDTO {\r\n \r\n}\r\n"
}
]
}
didOpen
[Trace - 4:55:26 PM] Sending notification 'textDocument/didOpen'.
Params: {
"textDocument": {
"uri": "file:///c%3A/Users/19141/Desktop/batis/src/main/java/com/example/batis/DAO.xml",
"languageId": "xml",
"version": 1,
"text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<!DOCTYPE mapper PUBLIC \"-//mybatis.org//DTD Mapper 3.0//EN\" \"https://mybatis.org/dtd/mybatis-3-mapper.dtd\">\r\n<mapper namespace=\"com.example.batis.DAO\">\r\n <update id=\"update\" parameterType=\"com.example.batis.Entity\"> \r\n UPDATE batis \r\n SET name=#{name}, age=#{age} \r\n WHERE id=#{id} \r\n </update>\r\n <select id=\"get\" resultType=\"com.example.batis.Entity\"> SELECT * FROM batis WHERE id=#{id} </select>\r\n</mapper>"
}
}
OSGi Bundle
plugin.xml
<plugin>
<extension
id="mybatisup.fragment"
point="org.eclipse.e4.workbench.model"> # 重点关注extension标签, point属性
<fragment
apply="notexists"
uri="fragment.e4xmi">
</fragment>
</extension>
</plugin>
manifest.MF
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Mybatisup
Bundle-SymbolicName: mybatisup;singleton:=true
Bundle-Version: 1.0.0
Require-Bundle: org.eclipse.jface, # 声明需要的依赖
org.eclipse.e4.ui.model.workbench,
org.eclipse.e4.ui.di,
org.eclipse.e4.ui.services,
org.eclipse.e4.core.di.annotations
Bundle-RequiredExecutionEnvironment: JavaSE-21
Import-Package: jakarta.annotation;version="[2.1.0,3.0.0)",
jakarta.inject;version="[2.0.0,3.0.0)",
org.osgi.framework;version="[1.10.0,2.0.0)"
Automatic-Module-Name: mybatisup
需求
- 编辑
mapper.xml时parameterTyperesultTypenamespace出现项目中类的提示 - 编辑
mapper.xml时补全文件顶部的xml声明 - 编辑
mapper.xml时类的跳转 - 编辑
mapper.xml时检查DAO是否有对应函数 - 编辑
DAO.java时检查mapper是否有对应SQL - 编辑
DAO.java时跳转到mapper.xml - 编辑
mapper.xml时sql语句的自动补全
更多推荐

所有评论(0)