如何编译并手动安装vscode插件

如何编译并手动安装vscode插件

Trae给出的步骤

  1. 安装依赖: cd yan/vscode-extension && npm install

  2. 编译插件: npm run compile

  3. 测试插件:按 F5 启动调试

  4. 打包插件: npm run package

  5. 发布到 VS Code 市场:参考 CHANGELOG.md

正确安装方法:

方法1:在 VS Code 中安装(推荐)

  1. 打开 VS Code (不是 Visual Studio)
  2. 按 Ctrl+Shift+X 打开扩展面板
  3. 点击右上角的 ... 菜单
  4. 选择 Install from VSIX...
  5. 选择生成的 yan-language-0.1.0.vsix 文件

方法2:使用命令行安装

复制代码
code --install-extension 
G:\dumategithub\newlisp\yan\vscode-extension\yan
-language-0.1.0.vsix

方法3:开发模式安装

  1. 打开 VS Code
  2. 打开 yan/vscode-extension 目录
  3. 按 F5 启动调试
  4. 新窗口会打开,插件已自动加载

发布到 VS Code 市场流程

1. 注册发布者账户

  1. 访问 Visual Studio Marketplace 发布者页面
  2. 使用 Microsoft 账户登录
  3. 创建发布者账户(需要提供发布者名称等信息)

2. 获取个人访问令牌(PAT)

  1. 访问 Azure DevOps 个人访问令牌页面
  2. 创建新令牌:
    • 名称 : 任意名称(如 vsce-publish )
    • 作用域 : 选择 Marketplace (Publish)
    • 过期时间 : 设置合适的有效期
  3. 复制生成的令牌( 只显示一次,务必保存 )

3. 登录 vsce

复制代码
cd yan/vscode-extension
vsce login <your-publisher-name>

然后粘贴之前复制的 PAT。

4. 打包插件

复制代码
vsce package

这会生成 yan-language-0.1.0.vsix 文件。

5. 发布插件

复制代码
vsce publish

或者直接发布本地包:

复制代码
vsce publish --packagePath yan-language-0.1.0.
vsix

6. 验证发布

访问 VS Code Marketplace ,搜索你的插件名称确认发布成功。

注意事项

  1. 图标 : 添加 icon.png (512x512 像素)到插件根目录
  2. README : 确保 README.md 内容完整
  3. 许可证 : 添加 LICENSE 文件
  4. 发布者名称 : 在 package.json 中设置正确的 publisher 字段

更新插件

更新版本时:

  1. 修改 package.json 中的 version 字段

  2. 更新 CHANGELOG.md

  3. 重新打包发布:

    vsce publish <new-version>

    vsce publish minor # 自动升级小版本
    vsce publish major # 自动升级大版本
    vsce publish patch # 自动升级补丁版本

参考文档 : VS Code 插件发布指南

实践

首先让Trae帮我们写插件,插件代码放在G:\dumategithub\newlisp\yan\vscode-extension 目录。

打包插件

进入目录G:\dumategithub\newlisp\yan\vscode-extension 执行npm run package打包插件:

npm run package

> yan-language@0.1.0 package

> vsce package

Executing prepublish script 'npm run vscode:prepublish'...

> yan-language@0.1.0 vscode:prepublish

> npm run compile

> yan-language@0.1.0 compile

> tsc -p ./

WARNING LICENSE, LICENSE.md, or LICENSE.txt not found

Do you want to continue? [y/N] y

INFO Files included in the VSIX:

yan-language-0.1.0.vsix

├─ [Content_Types].xml

├─ extension.vsixmanifest

└─ extension/

├─ CHANGELOG.md [0.47 KB]

├─ README.md [1.41 KB]

├─ debugger.js [2.1 KB]

├─ extension.js [3.61 KB]

├─ language-configuration.json [0.41 KB]

├─ package.json [1.85 KB]

├─ out/

│ ├─ completionProvider.js [7.28 KB]

│ ├─ diagnosticProvider.js [4.15 KB]

│ ├─ extension.js [4 KB]

│ ├─ hoverProvider.js [4.92 KB]

│ ├─ src/

│ │ ├─ completionProvider.js [7.28 KB]

│ │ ├─ diagnosticProvider.js [4.15 KB]

│ │ ├─ extension.js [4 KB]

│ │ └─ hoverProvider.js [4.92 KB]

│ └─ test/

│ ├─ extension.test.js [2.28 KB]

│ └─ runTest.js [1.96 KB]

├─ server/

│ └─ main.js [1.62 KB]

├─ snippets/

│ └─ yan.json [2.84 KB]

├─ syntaxes/

│ ├─ yan.tmLanguage.json [3.01 KB]

│ └─ yanmd.tmLanguage.json [1.02 KB]

└─ test/

├─ extension.test.js [2.28 KB]

└─ runTest.js [1.96 KB]

DONE Packaged: G:\dumategithub\newlisp\yan\vscode-extension\yan-language-0.1.0.vsix (24 files, 28.08 KB)

INFO The latest version of @vscode/vsce is 3.9.1 and you have 2.32.0.

Update it now: npm install -g @vscode/vsce

VScode导入插件

编译好的插件在:G:\dumategithub\newlisp\yan\vscode-extension\yan-language-0.1.0.vsix

直接命令行导入

复制代码
code --install-extension G:\dumategithub\newlisp\yan\vscode-extension\yan-language-0.1.0.vsix

导入成功

查看yan语言的高亮

发布到 VS Code 市场流程稍后再做。

调试

npm run compile编译报错

npm run compile

> yan-language@0.1.0 compile

> tsc -p ./

error TS6059: File 'G:/dumategithub/newlisp/yan/vscode-extension/test/extension.test.ts' is not under 'rootDir' 'G:/dumategithub/newlisp/yan/vscode-extension/src'. 'rootDir' is expected to contain all source files.

The file is in the program because:

Matched by default include pattern '**/*'

error TS6059: File 'G:/dumategithub/newlisp/yan/vscode-extension/test/runTest.ts' is not under 'rootDir' 'G:/dumategithub/newlisp/yan/vscode-extension/src'. 'rootDir' is expected to contain all source files.

The file is in the program because:

Matched by default include pattern '**/*'

Found 2 errors.

问题原因:

  1. tsconfig.json 中的 rootDir: "src" 与测试文件位置 test/ 冲突
  2. 缺少 @types/mocha 测试框架类型定义

修复内容:

修改 tsconfig.json :

  • 移除 rootDir 设置

  • 添加 include 明确指定编译目录: src//* 和 test/ /*

    修改 package.json :

  • 添加 @types/mocha: ^10.0.0

  • 添加 mocha: ^10.0.0

相关推荐
匆匆那年96714 小时前
VSCode 远程 Linux 使用Codex
linux·ide·vscode
渣渣灰958717 小时前
Windows 10 环境部署 Claude Code 教程
windows·vscode·calude code
lili00121 天前
CC GUI 插件架构剖析:如何为 JetBrains IDE 打造完整的 AI 编程工作台
java·ide·人工智能·python·架构·ai编程
慕言手记1 天前
IDEA 插件常用-2026版
java·ide·spring boot·intellij-idea·idea·intellij idea
nuoyigui98891 天前
向日葵远程无人值守,验证码不变
编辑器
我命由我123451 天前
Visual Studio - Visual Studio 注释快捷键
java·c语言·开发语言·c++·ide·java-ee·visual studio
码农小旋风1 天前
Codex 直接住进 JetBrains IDE 里:AI Agent 正在接管熟悉的开发入口
ide·人工智能
lifewange1 天前
Vim 统一替换(全局替换)
linux·编辑器·vim