如何编译并手动安装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

    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

相关推荐
zhangfeng11336 小时前
nano vim 有没有快速编辑的 方式 比如鼠标选择 ,然后快速修改 替换
编辑器·vim
salestina7 小时前
vscode迁移扩展目录
ide·vscode·编辑器
山峰哥8 小时前
数据库工程:Explain执行计划对比调优实战‌
大数据·数据库·sql·编辑器·深度优先
sunoo-2291 天前
【Linux 系统编程】学习第七天:线程属性 | 互斥锁 | 死锁 | 信号量 核心知识点 + 踩坑实战
linux·c语言·笔记·vscode·学习
铁手飞鹰1 天前
VSCode Python .embed 嵌入式环境黄色波浪线问题
ide·vscode·python
吴可可1231 天前
VSCode助力机械臂轨迹开发
vscode
樱花落木兰1 天前
Git 超全零基础教程|三区原理、全套命令、分支协作、冲突解决、IDEA 集成(面试必备)
ide·git·json·github
意法半导体STM321 天前
【官方原创】LAT1695转换STM32CubeIDE工程到STM32CubeIDE for Visual Studio Code
vscode·stm32·单片机·嵌入式硬件
Molesidy1 天前
【Embedded Development】基于VSCode+IAR插件的IAR工程开发环境的搭建
ide·vscode·编辑器
yangshuo12811 天前
用AI开发一个公网IP查询小工具:精准查询IDE/终端的真实出口IP(Python实战)
ide·人工智能·tcp/ip