Compare commits
50
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69ce015190 | ||
|
|
11417ee453 | ||
|
|
529e86a4c8 | ||
|
|
97158a6bf5 | ||
|
|
097da74608 | ||
|
|
09c3f89690 | ||
|
|
a3b3a22e41 | ||
|
|
f2de2b74e2 | ||
|
|
3810aa3062 | ||
|
|
9a2edf69e1 | ||
|
|
1ef34537b3 | ||
|
|
4f747d039a | ||
|
|
a01f6271df | ||
|
|
96a7ab00b1 | ||
|
|
f67b5f117b | ||
|
|
488b192760 | ||
|
|
b475c49ab8 | ||
|
|
3c6f06858b | ||
|
|
c5bcffb8e2 | ||
|
|
9efaaabd20 | ||
|
|
1bcff7a41f | ||
|
|
779a9e7791 | ||
|
|
3d1f18982f | ||
|
|
9c8263c873 | ||
|
|
1cee522f7c | ||
|
|
ac53cc823a | ||
|
|
1a4a41c5b3 | ||
|
|
31df509b20 | ||
|
|
7633b96db8 | ||
|
|
e61e74a586 | ||
|
|
e22fd8ad3b | ||
|
|
f85a3042d4 | ||
|
|
3a103abf76 | ||
|
|
e0eba07f34 | ||
|
|
4a60eadf8d | ||
|
|
5f96ae2f6a | ||
|
|
de39aa9e20 | ||
|
|
46ed5a5316 | ||
|
|
33f802e2ad | ||
|
|
f6f6df6dd2 | ||
|
|
fca85e8b08 | ||
|
|
b8c19fc545 | ||
|
|
1e9b83fe7a | ||
|
|
27fd795faf | ||
|
|
8312836004 | ||
|
|
fa843678d0 | ||
|
|
76e9bbb8ae | ||
|
|
cb2f4e4618 | ||
|
|
2406059fc2 | ||
|
|
b3fb132f58 |
No files matched your search
@@ -0,0 +1,6 @@
|
|||||||
|
.vscode-test/**
|
||||||
|
node_modules/**
|
||||||
|
out/**
|
||||||
|
*.vsix
|
||||||
|
npm-debug.log*
|
||||||
|
.DS_Store
|
||||||
Vendored
+18
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Run Extension",
|
||||||
|
"type": "extensionHost",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"--extensionDevelopmentPath=${workspaceFolder}",
|
||||||
|
"${workspaceFolder}/.."
|
||||||
|
],
|
||||||
|
"outFiles": [
|
||||||
|
"${workspaceFolder}/out/**/*.js"
|
||||||
|
],
|
||||||
|
"preLaunchTask": "npm: watch"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Vendored
+24
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"type": "npm",
|
||||||
|
"script": "watch",
|
||||||
|
"problemMatcher": "$tsc-watch",
|
||||||
|
"isBackground": true,
|
||||||
|
"presentation": {
|
||||||
|
"reveal": "never"
|
||||||
|
},
|
||||||
|
"group": {
|
||||||
|
"kind": "build",
|
||||||
|
"isDefault": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "npm",
|
||||||
|
"script": "compile",
|
||||||
|
"problemMatcher": "$tsc",
|
||||||
|
"group": "build"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
.vscode/**
|
||||||
|
.vscode-test/**
|
||||||
|
src/**
|
||||||
|
tsconfig.json
|
||||||
|
node_modules/**
|
||||||
|
.gitignore
|
||||||
|
**/*.map
|
||||||
|
**/*.ts
|
||||||
|
!out/**/*.js
|
||||||
|
media/logo-source.*
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
# VS Code 扩展维护指引
|
|
||||||
|
|
||||||
- 在本仓修改编辑器命令、诊断映射、导航、TextMate 和 VSIX。CLI 维护语言语义,View Tool 维护阅读和 Observation 展示。
|
|
||||||
- 使用公开 CLI 参数和已发布的 schema。打开与保存文件只触发静态检查,运行和预览由用户显式触发。
|
|
||||||
- 每项功能对照锁定的真实 CLI 独立构建和测试。历史实现从 `legacy-v2.8.0` 查看。
|
|
||||||
- 独立发布,依赖锁和平台证据按 [架构设计](docs/ARCHITECTURE.md) 记录。
|
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
# 架构(规范)
|
||||||
|
|
||||||
|
## 进程边界
|
||||||
|
|
||||||
|
```
|
||||||
|
┌─────────────────────────────┐
|
||||||
|
│ VS Code Extension Host │
|
||||||
|
│ · 语言配置 / TextMate │
|
||||||
|
│ · 命令、任务、Problems │
|
||||||
|
│ · (日后)LSP client │
|
||||||
|
│ · (日后)DAP client │
|
||||||
|
└─────────────┬───────────────┘
|
||||||
|
│ spawn / stdio
|
||||||
|
▼
|
||||||
|
┌─────────────────────────────┐
|
||||||
|
│ marqdo CLI(已安装) │
|
||||||
|
│ · run / catalog / debug │
|
||||||
|
│ · 诊断文案与行号真相 │
|
||||||
|
└─────────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
扩展 **不嵌入** Rust 解释器;分发上用户安装 CLI(或日后可选打包 sidecar,仍属后置决策)。
|
||||||
|
|
||||||
|
## 语言 id
|
||||||
|
|
||||||
|
- VS Code `languageId`: `marqdo`
|
||||||
|
- 文件:`*.mq.md`(必须保留 `.md` 后缀以便通用预览;用 `filename` / `filenamePattern` 关联,避免抢全部 Markdown)
|
||||||
|
|
||||||
|
## 与 Markdown 扩展共存
|
||||||
|
|
||||||
|
`.mq.md` 同时是 Markdown。策略:
|
||||||
|
|
||||||
|
1. **默认**用 Marqdo 语言模式(执行语义优先)。
|
||||||
|
2. 提供命令「以 Markdown 打开预览」调用内置 Markdown preview(不切换语言 id 也可预览时,优先不破坏高亮)。
|
||||||
|
3. 不禁用用户其它 Markdown 扩展;冲突时文档说明如何 `files.associations`。
|
||||||
|
|
||||||
|
## 诊断契约
|
||||||
|
|
||||||
|
CLI 用户可见失败:
|
||||||
|
|
||||||
|
```text
|
||||||
|
path:line:col: message
|
||||||
|
```
|
||||||
|
|
||||||
|
扩展将相对路径解析到工作区 URI,`severity` 为 0-based。与语言仓 P0 诊断模型一致。
|
||||||
|
|
||||||
|
## CLI 安装(扩展侧)
|
||||||
|
|
||||||
|
- 启动时(`onStartupFinished`)检测:**CLI 是否存在**、**版本是否 ≥ `marqdo.minCliVersion`(默认 0.1.0)**、**stdlib (`lib/`) 是否可用**。
|
||||||
|
- 任一不满足 → 提示用户,由其选择安装 / 打开 Releases / 不再询问。
|
||||||
|
- 安装物落到扩展 `globalStorage/cli/`,并写入 `marqdo.cliPath` / `marqdo.libPath`(spawn 时带 `MARQDO_LIB`)。
|
||||||
|
- 命令:`Marqdo: Install / Repair CLI`、`Marqdo: Check CLI Status`。
|
||||||
|
- 预编译自动安装以 **Windows x64** Release zip 为主。
|
||||||
|
|
||||||
|
## 调试(P3 → 现有入口)
|
||||||
|
- **已落地**:命令 `Marqdo: Open Debugger` 子进程启动 `marqdo debug --no-open`,再打开浏览器 / Simple Browser。
|
||||||
|
- **中期**:DAP 适配器包装现有 debug session API(`src/view/debug_api.rs` 语义),避免第三套断点模型。
|
||||||
|
|
||||||
|
## OKF / catalog(P3)
|
||||||
|
|
||||||
|
- 命令触发 `marqdo catalog <workspace> -o .marqdo`。
|
||||||
|
- 生成物已在语言仓 `.gitignore`(`.marqdo/`);扩展只负责调用与打开 `index.md` / `catalog.yaml`。
|
||||||
|
|
||||||
|
## 非目标(本阶段)
|
||||||
|
|
||||||
|
- 在扩展内实现完整树遍历 / 字节码
|
||||||
|
- 替代 `marqdo view` 静态站
|
||||||
|
- 强制用户登录或云服务
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
# 开发流程
|
||||||
|
|
||||||
|
## 环境
|
||||||
|
|
||||||
|
- Node.js 20+(LTS)
|
||||||
|
- VS Code 1.85+(`engines.vscode` 在 `package.json` 收紧)
|
||||||
|
- 本机已安装 **Marqdo CLI ≥ 0.1.0**(`marqdo --version`),用于 Run / catalog 集成
|
||||||
|
|
||||||
|
## 首次
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git checkout vscode-extension
|
||||||
|
cd vscode-extension
|
||||||
|
npm install
|
||||||
|
```
|
||||||
|
|
||||||
|
**推荐**:用 VS Code / Cursor **打开 `vscode-extension/` 文件夹**(不要只开仓库根),再按 F5(「Run Extension」)。Extension Development Host 会带上上级语言仓,便于打开 `public/*.mq.md` 验收。
|
||||||
|
|
||||||
|
验证:Language Mode = Marqdo;命令面板搜 `Marqdo: Run File` / `Open Debugger`。
|
||||||
|
|
||||||
|
## 日常脚本(约定)
|
||||||
|
|
||||||
|
| npm script | 用途 |
|
||||||
|
|------------|------|
|
||||||
|
| `npm run compile` | `tsc -p .` → `out/` |
|
||||||
|
| `npm run watch` | 监视编译 |
|
||||||
|
| `npm run lint` | 日后 ESLint(先可空) |
|
||||||
|
| `npm run package` | `vsce package` 打 `.vsix`(发布前) |
|
||||||
|
|
||||||
|
尚未加入的脚本:落地 `package.json` 时按上表补齐,勿引入与 Marqdo 语言仓抢戏的重型框架。
|
||||||
|
|
||||||
|
## 改语法 / 高亮
|
||||||
|
|
||||||
|
1. 对照语言仓 `doc/design/markdown-mapping.md`(以 `main` 为准)。
|
||||||
|
2. 改 `syntaxes/*.tmLanguage.json`(或等价)。
|
||||||
|
3. 用 `tests/` 与 `public/` 下真实 `.mq.md` 肉眼验收(Extension Host 打开语言仓 worktree)。
|
||||||
|
|
||||||
|
## 改 CLI 集成
|
||||||
|
|
||||||
|
- 子进程调用 `marqdo`,cwd = 工作区根或文件目录(与 `marqdo run` 导入/`lib/` 解析一致)。
|
||||||
|
- 解析 stderr 的 `path:line:col: message` 写入 `DiagnosticCollection`。
|
||||||
|
- **禁止**在扩展内重新实现解释器。
|
||||||
|
|
||||||
|
## 提交与推送
|
||||||
|
|
||||||
|
只在 **`vscode-extension` 分支** 提交本目录:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git status # 确认在 vscode-extension
|
||||||
|
git add vscode-extension
|
||||||
|
git commit -m "…"
|
||||||
|
git push -u origin vscode-extension
|
||||||
|
```
|
||||||
|
|
||||||
|
不要把本目录合并进 `main`(`main` 的 `.gitignore` 会忽略它)。
|
||||||
|
|
||||||
|
## 验收清单(P0 / P1)
|
||||||
|
|
||||||
|
- [ ] `.mq.md` 打开后 Language Mode = Marqdo
|
||||||
|
- [ ] `#` / `*` / `**` / `>` / 表格 / 注释行有可区分着色
|
||||||
|
- [ ] 函数体内 `---` / `***`、空返回 `****` 不与普通 Markdown 粗体完全糊成一团(尽力)
|
||||||
|
- [ ] F5 开发宿主可重复加载,无激活期未捕获异常
|
||||||
|
- [ ] `Marqdo: Run File` 成功时 Output 有输出;失败时 Problems 出现 `path:line:col`
|
||||||
|
- [ ] `Marqdo: Open Debugger` 拉起本地 debug 页(默认 `http://127.0.0.1:7430/`)
|
||||||
|
- [ ] 无 CLI 时启动提示 Install;确认后下载 bundle(含 stdlib)并可 `Run File`
|
||||||
|
|
||||||
|
设置:`marqdo.cliPath`、`marqdo.libPath`、`marqdo.autoInstall.checkOnStartup`、`marqdo.debugOpen`。
|
||||||
@@ -1,201 +0,0 @@
|
|||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
|
||||||
the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
|
||||||
other entities that control, are controlled by, or are under common
|
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
|
||||||
exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
|
||||||
including but not limited to software source code, documentation
|
|
||||||
source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
|
||||||
transformation or translation of a Source form, including but
|
|
||||||
not limited to compiled object code, generated documentation,
|
|
||||||
and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
|
||||||
Object form, made available under the License, as indicated by a
|
|
||||||
copyright notice that is included in or attached to the work
|
|
||||||
(an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
|
||||||
form, that is based on (or derived from) the Work and for which the
|
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
|
||||||
modifications, and in Source or Object form, provided that You
|
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
|
||||||
stating that You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
|
||||||
excluding those notices that do not pertain to any part of
|
|
||||||
the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
|
||||||
distribution, then any Derivative Works that You distribute must
|
|
||||||
include a readable copy of the attribution notices contained
|
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
|
||||||
the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
|
||||||
except as required for reasonable and customary use in describing the
|
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
|
||||||
unless required by applicable law (such as deliberate and grossly
|
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special,
|
|
||||||
incidental, or consequential damages of any character arising as a
|
|
||||||
result of this License or out of the use or inability to use the
|
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
|
||||||
other commercial damages or losses), even if such Contributor
|
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
||||||
or other liability obligations and/or rights consistent with this
|
|
||||||
License. However, in accepting such obligations, You may act only
|
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
|
||||||
defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
|
||||||
of your accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following
|
|
||||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
||||||
replaced with your own identifying information. (Don't include
|
|
||||||
the brackets!) The text should be enclosed in the appropriate
|
|
||||||
comment syntax for the file format. We also recommend that a
|
|
||||||
file or class name and description of purpose be included on the
|
|
||||||
same "printed page" as the copyright notice for easier
|
|
||||||
identification within third-party archives.
|
|
||||||
|
|
||||||
Copyright [yyyy] [name of copyright owner]
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
@@ -1,7 +1,109 @@
|
|||||||
# Marqdo for VS Code
|
# VS Code 扩展(分支工作区)
|
||||||
|
|
||||||
本仓负责 VS Code 中的 `.mq.md` 编辑体验、命令、诊断、导航与 VSIX 发布。扩展通过公开 CLI 接口取得语义,并可调用独立 View Tool 提供预览。
|
| | |
|
||||||
|
|---|---|
|
||||||
|
| 状态 | **三按钮 Run / View / Debug + CLI 检测**(扩展 v0.0.5;封面 logo;需 CLI ≥ **0.1.0**) |
|
||||||
|
| 日期 | 2026-08-05 |
|
||||||
|
| 语言仓 | [`cflmy/marqdo`](https://github.com/cflmy/marqdo) `main` |
|
||||||
|
| 扩展仓形态 | **同仓库专用分支** `vscode-extension`(本目录);`main` **不跟踪**本目录 |
|
||||||
|
|
||||||
[架构与迁移设计](docs/ARCHITECTURE.md) · [维护指引](AGENTS.md) · [Marqdo CLI 发行](https://git.cflmy.cn/cflmy/marqdo-cli/releases)
|
---
|
||||||
|
|
||||||
`main` 提供面向现行 CLI 的实现设计。原扩展的源码和独立提交历史已迁入 [legacy-v2.8.0](https://git.cflmy.cn/cflmy/marqdo-vscode/src/tag/legacy-v2.8.0)。这一标签用于审阅旧语法与 CLI 调用。现行版 VSIX 在真实兼容性验收后发布。
|
## 1. 与 `public` / `gh-pages` 的类比
|
||||||
|
|
||||||
|
| | `public/` 用户站 | `vscode-extension/` |
|
||||||
|
|--|------------------|---------------------|
|
||||||
|
| **main** | 跟踪可执行 `.mq.md` 源 | **忽略**本目录(不进 `main` 历史) |
|
||||||
|
| **专用分支** | `gh-pages`:生成 HTML | **`vscode-extension`**:扩展源码与规范 |
|
||||||
|
| **消费者** | 浏览器 / Pages | VS Code / Open VSX / Marketplace(日后) |
|
||||||
|
|
||||||
|
开发扩展时:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git fetch origin
|
||||||
|
git checkout vscode-extension
|
||||||
|
cd vscode-extension
|
||||||
|
npm install
|
||||||
|
```
|
||||||
|
|
||||||
|
回到语言本体:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git checkout main
|
||||||
|
```
|
||||||
|
|
||||||
|
可选:`git worktree add ../marqdo-vscode vscode-extension`,语言与扩展并行目录开发。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. 目标(对齐 v0.1.0 分发)
|
||||||
|
|
||||||
|
v0.1.0 已是「可解释 + view + debug CLI + catalog」的阶段性稳定小版本。扩展的第一阶段目标是 **编辑体验**,而不是一次做满 IDE:
|
||||||
|
|
||||||
|
| 优先级 | 能力 | 说明 |
|
||||||
|
|--------|------|------|
|
||||||
|
| **P0** | `.mq.md` 语言登记 + 基础语法高亮 | TextMate(已落地) |
|
||||||
|
| **P0** | 语言配置 | 括号 / 自动成对(已落地) |
|
||||||
|
| **P1** | 任务 / 命令 | `Marqdo: Run File` → `marqdo run`(已落地) |
|
||||||
|
| **P1** | 问题面板 | CLI `path:line:col` → Problems(已落地) |
|
||||||
|
| **P2** | 轻量语言特性 | 大纲(`#` 函数)、跳转到定义(同文件 / 导入) |
|
||||||
|
| **P3** | DAP / 调试 | 现已:`Marqdo: Open Debugger` 拉起 CLI debug 页;日后 DAP |
|
||||||
|
| **P3** | OKF / catalog | `Marqdo: Generate Catalog`(已落地轻量入口) |
|
||||||
|
|
||||||
|
原则:**扩展是 Marqdo CLI 的薄宿主**;语义以解释器与 [markdown-mapping.md](../doc/design/markdown-mapping.md) 为准,扩展不发明第二套语法。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. 目录约定(本分支)
|
||||||
|
|
||||||
|
```
|
||||||
|
vscode-extension/
|
||||||
|
README.md # 本文件:分支模型与目标
|
||||||
|
DEVELOPMENT.md # 日常开发流程、脚本、验收
|
||||||
|
ARCHITECTURE.md # 进程边界、与 CLI 的契约
|
||||||
|
package.json # 扩展清单(Marketplace id 待定)
|
||||||
|
tsconfig.json
|
||||||
|
.vscode/ # F5:Run Extension
|
||||||
|
.vscodeignore
|
||||||
|
src/
|
||||||
|
extension.ts # activate:命令 / 诊断
|
||||||
|
cli.ts # spawn marqdo
|
||||||
|
diagnostics.ts # path:line:col → Problems
|
||||||
|
syntaxes/ # TextMate 语法(P0)
|
||||||
|
marqdo.tmLanguage.json
|
||||||
|
language-configuration.json
|
||||||
|
```
|
||||||
|
|
||||||
|
生成物(`out/`、`node_modules/`、`*.vsix`)不入库;见本目录 `.gitignore`。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. 命名与发布(待拍板)
|
||||||
|
|
||||||
|
| 项 | 建议(可改) |
|
||||||
|
|----|--------------|
|
||||||
|
| 扩展显示名 | Marqdo |
|
||||||
|
| `publisher` | `cflmy`(或组织账号) |
|
||||||
|
| `name`(包名) | `marqdo` |
|
||||||
|
| 语言 id | `marqdo` |
|
||||||
|
| 文件关联 | `*.mq.md` |
|
||||||
|
|
||||||
|
发布渠道:先私有 / Open VSX,再 VS Marketplace。版本号与语言仓 **不必锁死同一 semver**,但发行说明应写明「需要 Marqdo CLI ≥ 0.1.0」。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. 文档索引(语言仓 `main`)
|
||||||
|
|
||||||
|
在 `main` 上仅保留指针,避免扩展实现泄漏进语言历史:
|
||||||
|
|
||||||
|
- [doc/design/vscode-extension.md](https://github.com/cflmy/marqdo/blob/main/doc/design/vscode-extension.md)(`main` 上的分支说明)
|
||||||
|
- 语法:[markdown-mapping.md](https://github.com/cflmy/marqdo/blob/main/doc/design/markdown-mapping.md)
|
||||||
|
- 诊断:[pipeline-debug.md](https://github.com/cflmy/marqdo/blob/main/doc/design/pipeline-debug.md)
|
||||||
|
- CLI debug:[view-debug.md](https://github.com/cflmy/marqdo/blob/main/doc/design/view-debug.md)
|
||||||
|
- Catalog / OKF:[catalog-cli.md](https://github.com/cflmy/marqdo/blob/main/doc/design/catalog-cli.md)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. 一句话
|
||||||
|
|
||||||
|
**语言在 `main`;编辑器宿主在 `vscode-extension` 分支。先高亮与 run/诊断,再 LSP/DAP;始终以 CLI 为真相源。**
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
# VS Code 扩展架构与迁移
|
|
||||||
|
|
||||||
## 所有权和调用边界
|
|
||||||
|
|
||||||
扩展将编辑器的文档、选择区、Problems 和命令接到 Marqdo 的公开能力。TextMate 提供词法着色与 Markdown 嵌入,语义导航消费 `marqdo.analysis`,运行消费 CLI 的退出码、输出和可选 Observation。CLI 负责解析、求值与权限,View Tool 负责阅读与可视化。三方各自独立构建和发布。
|
|
||||||
|
|
||||||
| 编辑器能力 | 公开依赖 | 验收要点 |
|
|
||||||
| --- | --- | --- |
|
|
||||||
| 文件关联与着色 | TextMate、现行语法示例 | `.mq.md` 文档的 Markdown 与代码段可读 |
|
|
||||||
| Problems | `marqdo check --json <file>` | 静态错误、文件范围及 UTF-16 位置映射 |
|
|
||||||
| 大纲与定义 | `marqdo check <file> --emit <analysis.json>`,Analysis revision 3 | 同文件及导入符号、过期结果、schema 与来源核验 |
|
|
||||||
| 显式运行 | `marqdo run <file> --mode pure` | 输出、取消、非零退出和权限拒绝 |
|
|
||||||
| 可选预览 | 已安装的 `marqdo view` | 独立工具检测、显式启动和进程回收 |
|
|
||||||
|
|
||||||
首版交付高亮、静态 Problems 与一次真实纯运行。大纲、定义、View 与额外能力随后独立验收。完整 LSP 或 DAP 由实际编辑器需求和公开契约评审决定。
|
|
||||||
|
|
||||||
## 实现边界
|
|
||||||
|
|
||||||
在根目录维护 `package.json`、`syntaxes/`、`language-configuration.json` 与小型 `src/`。入口注册 VS Code 生命周期与命令,CLI 适配层负责发现用户选定的可执行文件、组装参数与管理调用,诊断层负责结构化数据和编辑器范围的转换。Analysis 与 View 模块按实际消费者加入。`tests/` 存放可独立验证的 fixture,`out/` 和 `*.vsix` 由构建生成。
|
|
||||||
|
|
||||||
按 argv 数组启动明确配置的 CLI。工作区信任控制进程启动,设置与文件路径按工作区隔离。后台检查只处理已保存文档,按文档去抖、取消过期请求,并按版本丢弃旧结果。错误展示保留来源和退出码。CLI 不可用或不匹配时报告状态,并保留本地高亮。View 通过已安装的 Tool 运行,扩展持有进程柄并负责回收。
|
|
||||||
|
|
||||||
用户明确选择官方 CLI 制品。后续若增加托管安装,先验收平台范围、固定版本与摘要、下载验证、路径隔离与原子替换。运行前校验所需的公用协议,支持矩阵从实际发行验证生成。
|
|
||||||
|
|
||||||
## 验收与发行
|
|
||||||
|
|
||||||
组件 CI 使用锁定的 Node 依赖构建与打包 VSIX。诊断正负例覆盖中文与 UTF-16 边界、取消、坏 JSON、非零退出、输入路径与工作区信任。至少一个作业用实际发布的 CLI 验证静态检查和显式纯运行。声明支持的 VS Code 与操作系统组合验证 VSIX 安装、激活和卸载。
|
|
||||||
|
|
||||||
扩展独立版本记录扩展标识 `cflmy.marqdo`、兼容 CLI 范围与 Analysis 修订、VSIX 摘要及证据。首次市场发布前确认发布者权限和现有渠道归属。上游问题按 CLI 或 View 的接口责任提交,扩展保留自身回归。
|
|
||||||
|
|
||||||
## 历史来源
|
|
||||||
|
|
||||||
`legacy-v2.8.0` 从原 `vscode-extension` 分支 `1c6fea84d4d2e4a9af8b60e8e18a7f73a2a4f98f` 提取,包含语法、扩展清单、图标和 TypeScript 历史。按验证结果复用语言登记、图标和编辑器交互。旧安装器、旧 CLI 命令、文本错误解析和旧标准库设置由迁移实施逐项替换。
|
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"comments": {
|
||||||
|
"lineComment": null,
|
||||||
|
"blockComment": null
|
||||||
|
},
|
||||||
|
"brackets": [
|
||||||
|
["{", "}"],
|
||||||
|
["[", "]"],
|
||||||
|
["(", ")"]
|
||||||
|
],
|
||||||
|
"autoClosingPairs": [
|
||||||
|
{ "open": "{", "close": "}" },
|
||||||
|
{ "open": "[", "close": "]" },
|
||||||
|
{ "open": "(", "close": ")" },
|
||||||
|
{ "open": "`", "close": "`" },
|
||||||
|
{ "open": "*", "close": "*" }
|
||||||
|
],
|
||||||
|
"surroundingPairs": [
|
||||||
|
["{", "}"],
|
||||||
|
["[", "]"],
|
||||||
|
["(", ")"],
|
||||||
|
["`", "`"],
|
||||||
|
["*", "*"]
|
||||||
|
],
|
||||||
|
"onEnterRules": [
|
||||||
|
{
|
||||||
|
"beforeText": "^\\s*>\\s+\\S+.*$",
|
||||||
|
"action": { "indent": "indent" }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 262 B |
Generated
+3853
File diff suppressed because it is too large.
Load diff
+262
@@ -0,0 +1,262 @@
|
|||||||
|
{
|
||||||
|
"name": "marqdo",
|
||||||
|
"displayName": "Marqdo",
|
||||||
|
"description": "Language support for Marqdo (.mq.md) — code as documentation.",
|
||||||
|
"version": "2.8.0",
|
||||||
|
"publisher": "cflmy",
|
||||||
|
"icon": "media/icon.png",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/cflmy/marqdo.git"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/cflmy/marqdo/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/cflmy/marqdo/tree/main/vscode-extension",
|
||||||
|
"engines": {
|
||||||
|
"vscode": "^1.85.0"
|
||||||
|
},
|
||||||
|
"categories": [
|
||||||
|
"Programming Languages"
|
||||||
|
],
|
||||||
|
"keywords": [
|
||||||
|
"marqdo",
|
||||||
|
"markdown",
|
||||||
|
"mq.md"
|
||||||
|
],
|
||||||
|
"activationEvents": [
|
||||||
|
"onLanguage:marqdo",
|
||||||
|
"onStartupFinished"
|
||||||
|
],
|
||||||
|
"main": "./out/extension.js",
|
||||||
|
"contributes": {
|
||||||
|
"languages": [
|
||||||
|
{
|
||||||
|
"id": "marqdo",
|
||||||
|
"aliases": [
|
||||||
|
"Marqdo",
|
||||||
|
"marqdo"
|
||||||
|
],
|
||||||
|
"extensions": [
|
||||||
|
".mq.md"
|
||||||
|
],
|
||||||
|
"filenamePatterns": [
|
||||||
|
"*.mq.md"
|
||||||
|
],
|
||||||
|
"configuration": "./language-configuration.json"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"grammars": [
|
||||||
|
{
|
||||||
|
"language": "marqdo",
|
||||||
|
"scopeName": "source.marqdo",
|
||||||
|
"path": "./syntaxes/marqdo.tmLanguage.json"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"commands": [
|
||||||
|
{
|
||||||
|
"command": "marqdo.run",
|
||||||
|
"title": "Run File",
|
||||||
|
"shortTitle": "Run",
|
||||||
|
"category": "Marqdo",
|
||||||
|
"icon": "$(play)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "marqdo.view",
|
||||||
|
"title": "Open View",
|
||||||
|
"shortTitle": "View",
|
||||||
|
"category": "Marqdo",
|
||||||
|
"icon": "$(open-preview)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "marqdo.debug",
|
||||||
|
"title": "Open Debugger",
|
||||||
|
"shortTitle": "Debug",
|
||||||
|
"category": "Marqdo",
|
||||||
|
"icon": "$(debug-alt)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "marqdo.view.stop",
|
||||||
|
"title": "Stop View",
|
||||||
|
"category": "Marqdo",
|
||||||
|
"icon": "$(close)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "marqdo.debug.stop",
|
||||||
|
"title": "Stop Debugger",
|
||||||
|
"shortTitle": "Stop Debug",
|
||||||
|
"category": "Marqdo",
|
||||||
|
"icon": "$(debug-stop)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "marqdo.catalog",
|
||||||
|
"title": "Generate Catalog",
|
||||||
|
"category": "Marqdo",
|
||||||
|
"icon": "$(book)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "marqdo.showOutput",
|
||||||
|
"title": "Show Output",
|
||||||
|
"category": "Marqdo",
|
||||||
|
"icon": "$(output)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "marqdo.installCli",
|
||||||
|
"title": "Install / Repair CLI",
|
||||||
|
"category": "Marqdo",
|
||||||
|
"icon": "$(cloud-download)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "marqdo.checkCli",
|
||||||
|
"title": "Check CLI Status",
|
||||||
|
"category": "Marqdo",
|
||||||
|
"icon": "$(info)"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"menus": {
|
||||||
|
"editor/title": [
|
||||||
|
{
|
||||||
|
"command": "marqdo.run",
|
||||||
|
"when": "editorLangId == marqdo || resourceFilename =~ /\\.mq\\.md$/",
|
||||||
|
"group": "navigation@90"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "marqdo.view",
|
||||||
|
"when": "editorLangId == marqdo || resourceFilename =~ /\\.mq\\.md$/",
|
||||||
|
"group": "navigation@91"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "marqdo.debug",
|
||||||
|
"when": "editorLangId == marqdo || resourceFilename =~ /\\.mq\\.md$/",
|
||||||
|
"group": "navigation@92"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"commandPalette": [
|
||||||
|
{
|
||||||
|
"command": "marqdo.run",
|
||||||
|
"when": "editorLangId == marqdo || resourceFilename =~ /\\.mq\\.md$/"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "marqdo.view",
|
||||||
|
"when": "editorLangId == marqdo || resourceFilename =~ /\\.mq\\.md$/"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "marqdo.debug",
|
||||||
|
"when": "editorLangId == marqdo || resourceFilename =~ /\\.mq\\.md$/"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"keybindings": [
|
||||||
|
{
|
||||||
|
"command": "marqdo.run",
|
||||||
|
"key": "ctrl+shift+r",
|
||||||
|
"mac": "cmd+shift+r",
|
||||||
|
"when": "editorTextFocus && editorLangId == marqdo"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"configuration": {
|
||||||
|
"title": "Marqdo",
|
||||||
|
"properties": {
|
||||||
|
"marqdo.cliPath": {
|
||||||
|
"type": "string",
|
||||||
|
"default": "marqdo",
|
||||||
|
"description": "Path to the marqdo CLI executable (default: marqdo on PATH, or extension-managed install)."
|
||||||
|
},
|
||||||
|
"marqdo.managedCliPath": {
|
||||||
|
"type": "string",
|
||||||
|
"default": "",
|
||||||
|
"description": "Path written by Marqdo: Install / Repair CLI (managed binary)."
|
||||||
|
},
|
||||||
|
"marqdo.libPath": {
|
||||||
|
"type": "string",
|
||||||
|
"default": "",
|
||||||
|
"description": "Standard library root (sets MARQDO_LIB when spawning the CLI)."
|
||||||
|
},
|
||||||
|
"marqdo.autoInstall.checkOnStartup": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": true,
|
||||||
|
"description": "On startup, detect missing/outdated CLI or missing stdlib and offer install from GitHub Releases."
|
||||||
|
},
|
||||||
|
"marqdo.minCliVersion": {
|
||||||
|
"type": "string",
|
||||||
|
"default": "0.1.2",
|
||||||
|
"description": "Minimum required Marqdo CLI version (semver). Older installs trigger an upgrade prompt."
|
||||||
|
},
|
||||||
|
"marqdo.autoInstall.checkUpdates": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": true,
|
||||||
|
"description": "Periodically check GitHub Releases for newer CLI / extension versions."
|
||||||
|
},
|
||||||
|
"marqdo.diagnoseOnSave": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false,
|
||||||
|
"description": "Run `marqdo run` on save to refresh Problems (may hang on interactive input)."
|
||||||
|
},
|
||||||
|
"marqdo.runTimeoutMs": {
|
||||||
|
"type": "number",
|
||||||
|
"default": 60000,
|
||||||
|
"description": "Timeout for `marqdo run` / diagnose (milliseconds)."
|
||||||
|
},
|
||||||
|
"marqdo.viewHost": {
|
||||||
|
"type": "string",
|
||||||
|
"default": "127.0.0.1",
|
||||||
|
"description": "Host for `marqdo view`."
|
||||||
|
},
|
||||||
|
"marqdo.viewPort": {
|
||||||
|
"type": "number",
|
||||||
|
"default": 7429,
|
||||||
|
"description": "Port for `marqdo view`."
|
||||||
|
},
|
||||||
|
"marqdo.viewOpen": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"external",
|
||||||
|
"simpleBrowser"
|
||||||
|
],
|
||||||
|
"default": "external",
|
||||||
|
"description": "How to open the view UI after starting the server."
|
||||||
|
},
|
||||||
|
"marqdo.debugHost": {
|
||||||
|
"type": "string",
|
||||||
|
"default": "127.0.0.1",
|
||||||
|
"description": "Host for `marqdo debug`."
|
||||||
|
},
|
||||||
|
"marqdo.debugPort": {
|
||||||
|
"type": "number",
|
||||||
|
"default": 7430,
|
||||||
|
"description": "Port for `marqdo debug`."
|
||||||
|
},
|
||||||
|
"marqdo.debugOpen": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"external",
|
||||||
|
"simpleBrowser"
|
||||||
|
],
|
||||||
|
"default": "external",
|
||||||
|
"description": "How to open the debug UI after starting the server."
|
||||||
|
},
|
||||||
|
"marqdo.catalogOut": {
|
||||||
|
"type": "string",
|
||||||
|
"default": ".marqdo",
|
||||||
|
"description": "Output directory for `marqdo catalog`."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"configurationDefaults": {
|
||||||
|
"files.associations": {
|
||||||
|
"*.mq.md": "marqdo"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"vscode:prepublish": "npm run compile",
|
||||||
|
"compile": "tsc -p ./",
|
||||||
|
"watch": "tsc -watch -p ./"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^20.11.0",
|
||||||
|
"@types/vscode": "^1.85.0",
|
||||||
|
"@vscode/vsce": "^3.9.2",
|
||||||
|
"typescript": "^5.3.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
+193
@@ -0,0 +1,193 @@
|
|||||||
|
import * as vscode from "vscode";
|
||||||
|
import { spawn, spawnSync, type ChildProcessWithoutNullStreams } from "child_process";
|
||||||
|
import type { ExtensionContext } from "vscode";
|
||||||
|
|
||||||
|
export interface CliResult {
|
||||||
|
code: number | null;
|
||||||
|
stdout: string;
|
||||||
|
stderr: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
let resolveCli: (() => string) | undefined;
|
||||||
|
let resolveLib: (() => string | undefined) | undefined;
|
||||||
|
|
||||||
|
/** Wire install-aware path resolution from extension activate. */
|
||||||
|
export function configureCliResolution(
|
||||||
|
_context: ExtensionContext,
|
||||||
|
cli: () => string,
|
||||||
|
lib: () => string | undefined
|
||||||
|
): void {
|
||||||
|
resolveCli = cli;
|
||||||
|
resolveLib = lib;
|
||||||
|
}
|
||||||
|
|
||||||
|
function configuredPath(): string {
|
||||||
|
return (
|
||||||
|
vscode.workspace.getConfiguration("marqdo").get<string>("cliPath")?.trim() ||
|
||||||
|
"marqdo"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolveMarqdoCli(): string {
|
||||||
|
if (resolveCli) {
|
||||||
|
return resolveCli();
|
||||||
|
}
|
||||||
|
return configuredPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
function spawnEnv(): NodeJS.ProcessEnv {
|
||||||
|
const env = { ...process.env };
|
||||||
|
const lib = resolveLib?.();
|
||||||
|
if (lib) {
|
||||||
|
env.MARQDO_LIB = lib;
|
||||||
|
}
|
||||||
|
return env;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function workspaceCwd(prefer?: vscode.Uri): string {
|
||||||
|
if (prefer) {
|
||||||
|
const folder = vscode.workspace.getWorkspaceFolder(prefer);
|
||||||
|
if (folder) {
|
||||||
|
return folder.uri.fsPath;
|
||||||
|
}
|
||||||
|
return vscode.Uri.joinPath(prefer, "..").fsPath;
|
||||||
|
}
|
||||||
|
return vscode.workspace.workspaceFolders?.[0]?.uri.fsPath ?? process.cwd();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function runMarqdo(
|
||||||
|
args: string[],
|
||||||
|
options: { cwd: string; timeoutMs?: number }
|
||||||
|
): Promise<CliResult> {
|
||||||
|
const cli = resolveMarqdoCli();
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const child = spawn(cli, args, {
|
||||||
|
cwd: options.cwd,
|
||||||
|
shell: process.platform === "win32",
|
||||||
|
env: spawnEnv(),
|
||||||
|
});
|
||||||
|
let stdout = "";
|
||||||
|
let stderr = "";
|
||||||
|
let settled = false;
|
||||||
|
const finish = (code: number | null) => {
|
||||||
|
if (settled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
settled = true;
|
||||||
|
resolve({ code, stdout, stderr });
|
||||||
|
};
|
||||||
|
const timer =
|
||||||
|
options.timeoutMs && options.timeoutMs > 0
|
||||||
|
? setTimeout(() => {
|
||||||
|
child.kill();
|
||||||
|
finish(null);
|
||||||
|
}, options.timeoutMs)
|
||||||
|
: undefined;
|
||||||
|
child.stdout.on("data", (d: Buffer) => {
|
||||||
|
stdout += d.toString();
|
||||||
|
});
|
||||||
|
child.stderr.on("data", (d: Buffer) => {
|
||||||
|
stderr += d.toString();
|
||||||
|
});
|
||||||
|
child.on("error", (err) => {
|
||||||
|
if (timer) {
|
||||||
|
clearTimeout(timer);
|
||||||
|
}
|
||||||
|
stderr += err.message;
|
||||||
|
finish(1);
|
||||||
|
});
|
||||||
|
child.on("close", (code) => {
|
||||||
|
if (timer) {
|
||||||
|
clearTimeout(timer);
|
||||||
|
}
|
||||||
|
finish(code);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function probeMarqdo(
|
||||||
|
cliOverride?: string
|
||||||
|
): { ok: boolean; version?: string; detail: string } {
|
||||||
|
const cli = cliOverride ?? resolveMarqdoCli();
|
||||||
|
try {
|
||||||
|
const r = spawnSync(cli, ["--version"], {
|
||||||
|
encoding: "utf8",
|
||||||
|
shell: process.platform === "win32",
|
||||||
|
timeout: 8000,
|
||||||
|
env: spawnEnv(),
|
||||||
|
});
|
||||||
|
const out = `${r.stdout ?? ""}${r.stderr ?? ""}`.trim();
|
||||||
|
if (r.error) {
|
||||||
|
return { ok: false, detail: r.error.message };
|
||||||
|
}
|
||||||
|
if (r.status !== 0) {
|
||||||
|
return { ok: false, detail: out || `exit ${r.status}` };
|
||||||
|
}
|
||||||
|
return { ok: true, version: out, detail: out };
|
||||||
|
} catch (e) {
|
||||||
|
return { ok: false, detail: e instanceof Error ? e.message : String(e) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class LiveServer {
|
||||||
|
private proc: ChildProcessWithoutNullStreams | null = null;
|
||||||
|
private output: vscode.OutputChannel;
|
||||||
|
private label: string;
|
||||||
|
|
||||||
|
constructor(output: vscode.OutputChannel, label: string) {
|
||||||
|
this.output = output;
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
get running(): boolean {
|
||||||
|
return this.proc !== null && this.proc.exitCode === null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async start(
|
||||||
|
subcommand: "view" | "debug",
|
||||||
|
targetPath: string,
|
||||||
|
host: string,
|
||||||
|
port: number
|
||||||
|
): Promise<string> {
|
||||||
|
if (this.running) {
|
||||||
|
await this.stop();
|
||||||
|
}
|
||||||
|
const cli = resolveMarqdoCli();
|
||||||
|
const cwd = workspaceCwd(vscode.Uri.file(targetPath));
|
||||||
|
this.output.appendLine(
|
||||||
|
`$ ${cli} ${subcommand} ${targetPath} --host ${host} --port ${port} --no-open`
|
||||||
|
);
|
||||||
|
this.proc = spawn(
|
||||||
|
cli,
|
||||||
|
[subcommand, targetPath, "--host", host, "--port", String(port), "--no-open"],
|
||||||
|
{
|
||||||
|
cwd,
|
||||||
|
shell: process.platform === "win32",
|
||||||
|
env: spawnEnv(),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const url = `http://${host}:${port}/`;
|
||||||
|
this.proc.stdout.on("data", (d: Buffer) => this.output.append(d.toString()));
|
||||||
|
this.proc.stderr.on("data", (d: Buffer) => this.output.append(d.toString()));
|
||||||
|
this.proc.on("exit", (code) => {
|
||||||
|
this.output.appendLine(`[${this.label}] exited (${code})`);
|
||||||
|
this.proc = null;
|
||||||
|
});
|
||||||
|
this.proc.on("error", (err) => {
|
||||||
|
this.output.appendLine(`[${this.label}] ${err.message}`);
|
||||||
|
this.proc = null;
|
||||||
|
});
|
||||||
|
await new Promise((r) => setTimeout(r, 600));
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
async stop(): Promise<void> {
|
||||||
|
if (!this.proc) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const p = this.proc;
|
||||||
|
this.proc = null;
|
||||||
|
p.kill();
|
||||||
|
await new Promise((r) => setTimeout(r, 200));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,141 @@
|
|||||||
|
import * as vscode from "vscode";
|
||||||
|
import * as path from "path";
|
||||||
|
|
||||||
|
export function parseDiagnostics(
|
||||||
|
text: string,
|
||||||
|
fallbackUri: vscode.Uri,
|
||||||
|
cwd: string
|
||||||
|
): vscode.Diagnostic[] {
|
||||||
|
const out: vscode.Diagnostic[] = [];
|
||||||
|
for (const raw of text.split(/\r?\n/)) {
|
||||||
|
const line = raw.trim();
|
||||||
|
if (!line) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const parsed = parseDiagLine(line);
|
||||||
|
if (!parsed) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
out.push(
|
||||||
|
makeDiag(parsed.file, parsed.line, parsed.col, parsed.message, fallbackUri, cwd)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseDiagLine(
|
||||||
|
line: string
|
||||||
|
): { file: string; line: number; col: number; message: string } | undefined {
|
||||||
|
// Windows: E:\path\to\file.mq.md:7:1: message
|
||||||
|
const win = /^([A-Za-z]:[\\/][^:]*):(\d+):(\d+):\s*(.+)$/.exec(line);
|
||||||
|
if (win) {
|
||||||
|
return {
|
||||||
|
file: win[1],
|
||||||
|
line: Number(win[2]),
|
||||||
|
col: Number(win[3]),
|
||||||
|
message: win[4],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// Unix / relative: path/file.mq.md:7:1: message
|
||||||
|
const normal = /^(.+):(\d+):(\d+):\s*(.+)$/.exec(line);
|
||||||
|
if (normal) {
|
||||||
|
return {
|
||||||
|
file: normal[1],
|
||||||
|
line: Number(normal[2]),
|
||||||
|
col: Number(normal[3]),
|
||||||
|
message: normal[4],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const spanOnly = /^(\d+):(\d+):\s*(.+)$/.exec(line);
|
||||||
|
if (spanOnly) {
|
||||||
|
return {
|
||||||
|
file: "",
|
||||||
|
line: Number(spanOnly[1]),
|
||||||
|
col: Number(spanOnly[2]),
|
||||||
|
message: spanOnly[3],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeDiag(
|
||||||
|
filePath: string,
|
||||||
|
line1: number,
|
||||||
|
col1: number,
|
||||||
|
message: string,
|
||||||
|
fallbackUri: vscode.Uri,
|
||||||
|
cwd: string
|
||||||
|
): vscode.Diagnostic {
|
||||||
|
const line = Math.max(0, line1 - 1);
|
||||||
|
const col = Math.max(0, col1 - 1);
|
||||||
|
const range = new vscode.Range(line, col, line, Math.max(col + 1, col));
|
||||||
|
const diag = new vscode.Diagnostic(range, message, vscode.DiagnosticSeverity.Error);
|
||||||
|
diag.source = "marqdo";
|
||||||
|
(diag as vscode.Diagnostic & { targetPath?: string }).targetPath = resolvePath(
|
||||||
|
filePath,
|
||||||
|
fallbackUri,
|
||||||
|
cwd
|
||||||
|
);
|
||||||
|
return diag;
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolvePath(filePath: string, fallbackUri: vscode.Uri, cwd: string): string {
|
||||||
|
if (!filePath) {
|
||||||
|
return fallbackUri.fsPath;
|
||||||
|
}
|
||||||
|
if (path.isAbsolute(filePath)) {
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
return path.resolve(cwd, filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
export class DiagnosticBag {
|
||||||
|
private readonly collection: vscode.DiagnosticCollection;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.collection = vscode.languages.createDiagnosticCollection("marqdo");
|
||||||
|
}
|
||||||
|
|
||||||
|
get disposable(): vscode.Disposable {
|
||||||
|
return this.collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
clear(uri?: vscode.Uri): void {
|
||||||
|
if (uri) {
|
||||||
|
this.collection.delete(uri);
|
||||||
|
} else {
|
||||||
|
this.collection.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setFromCli(text: string, fallbackUri: vscode.Uri, cwd: string): void {
|
||||||
|
const parsed = parseDiagnostics(text, fallbackUri, cwd);
|
||||||
|
const byFile = new Map<string, vscode.Diagnostic[]>();
|
||||||
|
for (const d of parsed) {
|
||||||
|
const target =
|
||||||
|
(d as vscode.Diagnostic & { targetPath?: string }).targetPath ?? fallbackUri.fsPath;
|
||||||
|
const list = byFile.get(target) ?? [];
|
||||||
|
list.push(d);
|
||||||
|
byFile.set(target, list);
|
||||||
|
}
|
||||||
|
if (byFile.size === 0) {
|
||||||
|
const trimmed = text.trim();
|
||||||
|
if (trimmed) {
|
||||||
|
const range = new vscode.Range(0, 0, 0, 1);
|
||||||
|
this.collection.set(fallbackUri, [
|
||||||
|
new vscode.Diagnostic(
|
||||||
|
range,
|
||||||
|
trimmed.split(/\r?\n/)[0],
|
||||||
|
vscode.DiagnosticSeverity.Error
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
this.collection.delete(fallbackUri);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (const [file, diags] of byFile) {
|
||||||
|
this.collection.set(vscode.Uri.file(file), diags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,307 @@
|
|||||||
|
import * as vscode from "vscode";
|
||||||
|
import { LiveServer, configureCliResolution, runMarqdo, workspaceCwd } from "./cli";
|
||||||
|
import { DiagnosticBag } from "./diagnostics";
|
||||||
|
import {
|
||||||
|
checkInstallStatus,
|
||||||
|
installFromGitHub,
|
||||||
|
promptIfNeeded,
|
||||||
|
resetSkipPrompt,
|
||||||
|
resolveCliPath,
|
||||||
|
resolveLibEnv,
|
||||||
|
} from "./install";
|
||||||
|
import { checkForUpdates } from "./updateCheck";
|
||||||
|
|
||||||
|
let output: vscode.OutputChannel;
|
||||||
|
let diagnostics: DiagnosticBag;
|
||||||
|
let viewServer: LiveServer;
|
||||||
|
let debugServer: LiveServer;
|
||||||
|
let extContext: vscode.ExtensionContext;
|
||||||
|
|
||||||
|
export function activate(context: vscode.ExtensionContext): void {
|
||||||
|
extContext = context;
|
||||||
|
output = vscode.window.createOutputChannel("Marqdo");
|
||||||
|
diagnostics = new DiagnosticBag();
|
||||||
|
viewServer = new LiveServer(output, "view");
|
||||||
|
debugServer = new LiveServer(output, "debug");
|
||||||
|
|
||||||
|
configureCliResolution(
|
||||||
|
context,
|
||||||
|
() => resolveCliPath(context),
|
||||||
|
() => resolveLibEnv(context)
|
||||||
|
);
|
||||||
|
|
||||||
|
context.subscriptions.push(
|
||||||
|
output,
|
||||||
|
diagnostics.disposable,
|
||||||
|
vscode.commands.registerCommand("marqdo.run", () => runActiveFile()),
|
||||||
|
vscode.commands.registerCommand("marqdo.view", () => startView()),
|
||||||
|
vscode.commands.registerCommand("marqdo.debug", () => startDebug()),
|
||||||
|
vscode.commands.registerCommand("marqdo.debug.stop", () => stopDebug()),
|
||||||
|
vscode.commands.registerCommand("marqdo.view.stop", () => stopView()),
|
||||||
|
vscode.commands.registerCommand("marqdo.catalog", () => runCatalog()),
|
||||||
|
vscode.commands.registerCommand("marqdo.showOutput", () => output.show(true)),
|
||||||
|
vscode.commands.registerCommand("marqdo.installCli", () => installCli()),
|
||||||
|
vscode.commands.registerCommand("marqdo.checkCli", () => checkCli())
|
||||||
|
);
|
||||||
|
|
||||||
|
context.subscriptions.push(
|
||||||
|
vscode.workspace.onDidSaveTextDocument((doc) => {
|
||||||
|
if (doc.languageId === "marqdo" && autoDiagnose()) {
|
||||||
|
void diagnoseDocument(doc);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
void (async () => {
|
||||||
|
await promptIfNeeded(context, output);
|
||||||
|
const status = checkInstallStatus(context);
|
||||||
|
await checkForUpdates(context, output, status.version);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deactivate(): void {
|
||||||
|
void viewServer?.stop();
|
||||||
|
void debugServer?.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
function autoDiagnose(): boolean {
|
||||||
|
return vscode.workspace.getConfiguration("marqdo").get<boolean>("diagnoseOnSave") ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function installCli(): Promise<void> {
|
||||||
|
await resetSkipPrompt(extContext);
|
||||||
|
const status = checkInstallStatus(extContext);
|
||||||
|
try {
|
||||||
|
const mode = status.suggestedMode ?? "bundle";
|
||||||
|
await installFromGitHub(extContext, output, mode);
|
||||||
|
} catch (e) {
|
||||||
|
const err = e instanceof Error ? e.message : String(e);
|
||||||
|
output.appendLine(`[install] ${err}`);
|
||||||
|
const open = await vscode.window.showErrorMessage(`Marqdo install failed: ${err}`, "Open Releases");
|
||||||
|
if (open) {
|
||||||
|
await vscode.env.openExternal(vscode.Uri.parse("https://github.com/cflmy/marqdo/releases"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkCli(): Promise<void> {
|
||||||
|
const status = checkInstallStatus(extContext);
|
||||||
|
output.appendLine(`[check] ${status.detail}`);
|
||||||
|
if (status.cliOk && status.versionOk && status.libOk) {
|
||||||
|
void vscode.window.showInformationMessage(
|
||||||
|
`Marqdo ready: ${status.parsedVersion ?? status.version} (≥ ${status.requiredVersion}), stdlib OK`
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const choice = await vscode.window.showWarningMessage(
|
||||||
|
status.detail,
|
||||||
|
"Install / Repair",
|
||||||
|
"Open Releases"
|
||||||
|
);
|
||||||
|
if (choice === "Install / Repair") {
|
||||||
|
await installCli();
|
||||||
|
} else if (choice === "Open Releases") {
|
||||||
|
await vscode.env.openExternal(vscode.Uri.parse("https://github.com/cflmy/marqdo/releases"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function activeMqDoc(): vscode.TextDocument | undefined {
|
||||||
|
const doc = vscode.window.activeTextEditor?.document;
|
||||||
|
if (!doc) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
if (doc.languageId === "marqdo" || doc.fileName.endsWith(".mq.md")) {
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function ensureCliOrOfferInstall(): Promise<boolean> {
|
||||||
|
const status = checkInstallStatus(extContext);
|
||||||
|
if (status.cliOk && status.versionOk && status.libOk) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (status.cliOk && status.versionOk && !status.libOk) {
|
||||||
|
const choice = await vscode.window.showWarningMessage(
|
||||||
|
"Standard library (lib/) is missing. Continue anyway, or install stdlib?",
|
||||||
|
"Install stdlib",
|
||||||
|
"Continue",
|
||||||
|
"Cancel"
|
||||||
|
);
|
||||||
|
if (choice === "Install stdlib") {
|
||||||
|
await installCli();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (choice === "Continue") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const label = !status.cliOk
|
||||||
|
? "Marqdo CLI not found. Install the official release (includes stdlib)?"
|
||||||
|
: `Marqdo CLI is below ${status.requiredVersion}. Upgrade now?`;
|
||||||
|
const choice = await vscode.window.showWarningMessage(label, "Install", "Cancel");
|
||||||
|
if (choice === "Install") {
|
||||||
|
await installCli();
|
||||||
|
const again = checkInstallStatus(extContext);
|
||||||
|
return again.cliOk && again.versionOk;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveTargetPath(): string | undefined {
|
||||||
|
const doc = activeMqDoc();
|
||||||
|
const folder = vscode.workspace.workspaceFolders?.[0];
|
||||||
|
return doc?.uri.fsPath ?? folder?.uri.fsPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function openUrl(url: string, settingKey: "viewOpen" | "debugOpen"): Promise<void> {
|
||||||
|
const open =
|
||||||
|
vscode.workspace.getConfiguration("marqdo").get<string>(settingKey) ?? "external";
|
||||||
|
if (open === "simpleBrowser") {
|
||||||
|
await vscode.commands.executeCommand("simpleBrowser.show", url);
|
||||||
|
} else {
|
||||||
|
await vscode.env.openExternal(vscode.Uri.parse(url));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function runActiveFile(): Promise<void> {
|
||||||
|
if (!(await ensureCliOrOfferInstall())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const doc = activeMqDoc();
|
||||||
|
if (!doc) {
|
||||||
|
void vscode.window.showWarningMessage("Open a .mq.md file to run.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (doc.isDirty) {
|
||||||
|
await doc.save();
|
||||||
|
}
|
||||||
|
const cwd = workspaceCwd(doc.uri);
|
||||||
|
output.show(true);
|
||||||
|
output.appendLine(`$ marqdo run ${doc.uri.fsPath}`);
|
||||||
|
const result = await runMarqdo(["run", doc.uri.fsPath], {
|
||||||
|
cwd,
|
||||||
|
timeoutMs: vscode.workspace.getConfiguration("marqdo").get<number>("runTimeoutMs") ?? 60000,
|
||||||
|
});
|
||||||
|
if (result.stdout.trim()) {
|
||||||
|
output.appendLine(result.stdout.trimEnd());
|
||||||
|
}
|
||||||
|
if (result.stderr.trim()) {
|
||||||
|
output.appendLine(result.stderr.trimEnd());
|
||||||
|
}
|
||||||
|
if (result.code === 0) {
|
||||||
|
diagnostics.clear(doc.uri);
|
||||||
|
void vscode.window.setStatusBarMessage("Marqdo: run ok", 3000);
|
||||||
|
} else {
|
||||||
|
diagnostics.setFromCli(result.stderr || result.stdout, doc.uri, cwd);
|
||||||
|
void vscode.window.showErrorMessage("Marqdo: run failed (see Problems / Output)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function diagnoseDocument(doc: vscode.TextDocument): Promise<void> {
|
||||||
|
const cwd = workspaceCwd(doc.uri);
|
||||||
|
const result = await runMarqdo(["run", doc.uri.fsPath], {
|
||||||
|
cwd,
|
||||||
|
timeoutMs: vscode.workspace.getConfiguration("marqdo").get<number>("runTimeoutMs") ?? 60000,
|
||||||
|
});
|
||||||
|
if (result.code === 0) {
|
||||||
|
diagnostics.clear(doc.uri);
|
||||||
|
} else {
|
||||||
|
diagnostics.setFromCli(result.stderr || result.stdout, doc.uri, cwd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function startView(): Promise<void> {
|
||||||
|
if (!(await ensureCliOrOfferInstall())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const target = resolveTargetPath();
|
||||||
|
if (!target) {
|
||||||
|
void vscode.window.showWarningMessage("Open a folder or .mq.md file for view.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const cfg = vscode.workspace.getConfiguration("marqdo");
|
||||||
|
const host = cfg.get<string>("viewHost") ?? "127.0.0.1";
|
||||||
|
const port = cfg.get<number>("viewPort") ?? 7429;
|
||||||
|
output.show(true);
|
||||||
|
try {
|
||||||
|
const url = await viewServer.start("view", target, host, port);
|
||||||
|
await openUrl(url, "viewOpen");
|
||||||
|
void vscode.window.setStatusBarMessage(`Marqdo view: ${url}`, 5000);
|
||||||
|
} catch (e) {
|
||||||
|
void vscode.window.showErrorMessage(
|
||||||
|
`Marqdo view failed: ${e instanceof Error ? e.message : String(e)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function startDebug(): Promise<void> {
|
||||||
|
if (!(await ensureCliOrOfferInstall())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const target = resolveTargetPath();
|
||||||
|
if (!target) {
|
||||||
|
void vscode.window.showWarningMessage("Open a folder or .mq.md file to debug.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const cfg = vscode.workspace.getConfiguration("marqdo");
|
||||||
|
const host = cfg.get<string>("debugHost") ?? "127.0.0.1";
|
||||||
|
const port = cfg.get<number>("debugPort") ?? 7430;
|
||||||
|
output.show(true);
|
||||||
|
try {
|
||||||
|
const url = await debugServer.start("debug", target, host, port);
|
||||||
|
await openUrl(url, "debugOpen");
|
||||||
|
void vscode.window.setStatusBarMessage(`Marqdo debug: ${url}`, 5000);
|
||||||
|
} catch (e) {
|
||||||
|
void vscode.window.showErrorMessage(
|
||||||
|
`Marqdo debug failed: ${e instanceof Error ? e.message : String(e)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function stopView(): Promise<void> {
|
||||||
|
await viewServer.stop();
|
||||||
|
void vscode.window.setStatusBarMessage("Marqdo view stopped", 3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function stopDebug(): Promise<void> {
|
||||||
|
await debugServer.stop();
|
||||||
|
void vscode.window.setStatusBarMessage("Marqdo debug stopped", 3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function runCatalog(): Promise<void> {
|
||||||
|
if (!(await ensureCliOrOfferInstall())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const folder = vscode.workspace.workspaceFolders?.[0];
|
||||||
|
if (!folder) {
|
||||||
|
void vscode.window.showWarningMessage("Open a workspace folder for catalog.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const outDir =
|
||||||
|
vscode.workspace.getConfiguration("marqdo").get<string>("catalogOut") ?? ".marqdo";
|
||||||
|
output.show(true);
|
||||||
|
output.appendLine(`$ marqdo catalog ${folder.uri.fsPath} -o ${outDir}`);
|
||||||
|
const result = await runMarqdo(["catalog", folder.uri.fsPath, "-o", outDir], {
|
||||||
|
cwd: folder.uri.fsPath,
|
||||||
|
timeoutMs: 120000,
|
||||||
|
});
|
||||||
|
if (result.stdout.trim()) {
|
||||||
|
output.appendLine(result.stdout.trimEnd());
|
||||||
|
}
|
||||||
|
if (result.stderr.trim()) {
|
||||||
|
output.appendLine(result.stderr.trimEnd());
|
||||||
|
}
|
||||||
|
if (result.code === 0) {
|
||||||
|
const index = vscode.Uri.joinPath(folder.uri, outDir, "index.md");
|
||||||
|
try {
|
||||||
|
const doc = await vscode.workspace.openTextDocument(index);
|
||||||
|
await vscode.window.showTextDocument(doc, { preview: true });
|
||||||
|
} catch {
|
||||||
|
void vscode.window.showInformationMessage(`Marqdo catalog written to ${outDir}`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
void vscode.window.showErrorMessage("Marqdo catalog failed (see Output)");
|
||||||
|
}
|
||||||
|
}
|
||||||
+499
@@ -0,0 +1,499 @@
|
|||||||
|
import * as vscode from "vscode";
|
||||||
|
import * as fs from "fs";
|
||||||
|
import * as path from "path";
|
||||||
|
import * as os from "os";
|
||||||
|
import { spawnSync } from "child_process";
|
||||||
|
import { probeMarqdo } from "./cli";
|
||||||
|
|
||||||
|
const REPO = "cflmy/marqdo";
|
||||||
|
const SKIP_KEY = "marqdo.skipInstallPrompt";
|
||||||
|
const MANAGED_DIR = "cli";
|
||||||
|
/** CLI builds from this version ship stdlib inside the binary. */
|
||||||
|
export const EMBEDDED_STDLIB_SINCE = "0.1.2";
|
||||||
|
|
||||||
|
export type InstallStatus = {
|
||||||
|
cliOk: boolean;
|
||||||
|
libOk: boolean;
|
||||||
|
versionOk: boolean;
|
||||||
|
version?: string;
|
||||||
|
parsedVersion?: string;
|
||||||
|
requiredVersion: string;
|
||||||
|
cliPath?: string;
|
||||||
|
libRoot?: string;
|
||||||
|
detail: string;
|
||||||
|
/** Suggested install mode when not fully ready */
|
||||||
|
suggestedMode?: "bundle" | "stdlib";
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Parse first semver-like token from `marqdo --version` output. */
|
||||||
|
export function parseCliVersion(raw: string): string | undefined {
|
||||||
|
const m = raw.match(/(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)/);
|
||||||
|
return m?.[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Compare a.b.c semver (pre-release suffix ignored for ordering). Returns <0 if a<b. */
|
||||||
|
export function compareSemver(a: string, b: string): number {
|
||||||
|
const pa = a.split("-")[0].split(".").map((x) => Number.parseInt(x, 10) || 0);
|
||||||
|
const pb = b.split("-")[0].split(".").map((x) => Number.parseInt(x, 10) || 0);
|
||||||
|
for (let i = 0; i < 3; i++) {
|
||||||
|
const d = (pa[i] ?? 0) - (pb[i] ?? 0);
|
||||||
|
if (d !== 0) {
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function requiredVersion(): string {
|
||||||
|
return cfg().get<string>("minCliVersion")?.trim() || "0.1.0";
|
||||||
|
}
|
||||||
|
|
||||||
|
type GhAsset = { name: string; browser_download_url: string };
|
||||||
|
type GhRelease = {
|
||||||
|
tag_name: string;
|
||||||
|
html_url: string;
|
||||||
|
assets: GhAsset[];
|
||||||
|
};
|
||||||
|
|
||||||
|
function cfg() {
|
||||||
|
return vscode.workspace.getConfiguration("marqdo");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function managedRoot(context: vscode.ExtensionContext): string {
|
||||||
|
return path.join(context.globalStorageUri.fsPath, MANAGED_DIR);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function managedExePath(context: vscode.ExtensionContext): string {
|
||||||
|
const name = process.platform === "win32" ? "marqdo.exe" : "marqdo";
|
||||||
|
return path.join(managedRoot(context), name);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function managedLibRoot(context: vscode.ExtensionContext): string {
|
||||||
|
// Release zip layout: marqdo.exe + lib/… → MARQDO_LIB can be the dir that contains lib/, or lib itself.
|
||||||
|
// load.rs: root.join(remainder) and root.join("lib").join(remainder)
|
||||||
|
return managedRoot(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Prefer explicit setting, then managed install, then PATH. */
|
||||||
|
export function resolveCliPath(context?: vscode.ExtensionContext): string {
|
||||||
|
const setting = cfg().get<string>("cliPath")?.trim() || "marqdo";
|
||||||
|
if (setting !== "marqdo") {
|
||||||
|
return setting;
|
||||||
|
}
|
||||||
|
if (context) {
|
||||||
|
const managed = managedExePath(context);
|
||||||
|
if (fs.existsSync(managed)) {
|
||||||
|
return managed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const stored = cfg().get<string>("managedCliPath")?.trim();
|
||||||
|
if (stored && fs.existsSync(stored)) {
|
||||||
|
return stored;
|
||||||
|
}
|
||||||
|
return "marqdo";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolveLibEnv(context?: vscode.ExtensionContext): string | undefined {
|
||||||
|
const setting = cfg().get<string>("libPath")?.trim();
|
||||||
|
if (setting) {
|
||||||
|
return setting;
|
||||||
|
}
|
||||||
|
if (context) {
|
||||||
|
const root = managedLibRoot(context);
|
||||||
|
if (fs.existsSync(path.join(root, "lib")) || looksLikeLibRoot(root)) {
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function looksLikeLibRoot(root: string): boolean {
|
||||||
|
return (
|
||||||
|
fs.existsSync(path.join(root, "math.mq.md")) ||
|
||||||
|
fs.existsSync(path.join(root, "text.mq.md")) ||
|
||||||
|
fs.existsSync(path.join(root, "lib", "math.mq.md"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function findExeDir(cliPath: string): string | undefined {
|
||||||
|
if (cliPath.includes(path.sep) || cliPath.includes("/") || /\.exe$/i.test(cliPath)) {
|
||||||
|
if (fs.existsSync(cliPath)) {
|
||||||
|
return path.dirname(cliPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Resolve via where/which
|
||||||
|
const cmd = process.platform === "win32" ? "where" : "which";
|
||||||
|
const r = spawnSync(cmd, [cliPath === "marqdo" && process.platform === "win32" ? "marqdo.exe" : cliPath], {
|
||||||
|
encoding: "utf8",
|
||||||
|
shell: true,
|
||||||
|
});
|
||||||
|
const first = (r.stdout || "")
|
||||||
|
.split(/\r?\n/)
|
||||||
|
.map((s) => s.trim())
|
||||||
|
.find((s) => s.length > 0);
|
||||||
|
if (first && fs.existsSync(first)) {
|
||||||
|
return path.dirname(first);
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function stdlibPresent(cliPath: string, context?: vscode.ExtensionContext): { ok: boolean; root?: string } {
|
||||||
|
const envLib = process.env.MARQDO_LIB;
|
||||||
|
if (envLib && looksLikeLibRoot(envLib)) {
|
||||||
|
return { ok: true, root: envLib };
|
||||||
|
}
|
||||||
|
const configured = resolveLibEnv(context);
|
||||||
|
if (configured && looksLikeLibRoot(configured)) {
|
||||||
|
return { ok: true, root: configured };
|
||||||
|
}
|
||||||
|
const dir = findExeDir(cliPath);
|
||||||
|
if (dir) {
|
||||||
|
if (looksLikeLibRoot(dir) || looksLikeLibRoot(path.join(dir, "lib"))) {
|
||||||
|
return { ok: true, root: dir };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Workspace ./lib
|
||||||
|
const ws = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath;
|
||||||
|
if (ws && looksLikeLibRoot(path.join(ws, "lib"))) {
|
||||||
|
return { ok: true, root: path.join(ws, "lib") };
|
||||||
|
}
|
||||||
|
return { ok: false };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function checkInstallStatus(context: vscode.ExtensionContext): InstallStatus {
|
||||||
|
const need = requiredVersion();
|
||||||
|
const cliPath = resolveCliPath(context);
|
||||||
|
const probe = probeMarqdo(cliPath);
|
||||||
|
if (!probe.ok) {
|
||||||
|
return {
|
||||||
|
cliOk: false,
|
||||||
|
libOk: false,
|
||||||
|
versionOk: false,
|
||||||
|
requiredVersion: need,
|
||||||
|
cliPath,
|
||||||
|
detail: `Marqdo CLI not found (${probe.detail}). Need ≥ ${need} with stdlib.`,
|
||||||
|
suggestedMode: "bundle",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const parsed = parseCliVersion(probe.version ?? "");
|
||||||
|
const versionOk = parsed !== undefined && compareSemver(parsed, need) >= 0;
|
||||||
|
let lib = stdlibPresent(cliPath, context);
|
||||||
|
if (
|
||||||
|
parsed &&
|
||||||
|
compareSemver(parsed, EMBEDDED_STDLIB_SINCE) >= 0 &&
|
||||||
|
!lib.ok
|
||||||
|
) {
|
||||||
|
lib = { ok: true, root: "(embedded in binary)" };
|
||||||
|
}
|
||||||
|
|
||||||
|
let suggestedMode: "bundle" | "stdlib" | undefined;
|
||||||
|
if (!versionOk) {
|
||||||
|
suggestedMode = "bundle";
|
||||||
|
} else if (!lib.ok) {
|
||||||
|
suggestedMode = "stdlib";
|
||||||
|
}
|
||||||
|
|
||||||
|
const parts: string[] = [`CLI ${probe.version}`];
|
||||||
|
if (!versionOk) {
|
||||||
|
parts.push(`version too old (need ≥ ${need}${parsed ? `, found ${parsed}` : ""})`);
|
||||||
|
}
|
||||||
|
if (lib.ok) {
|
||||||
|
parts.push(`stdlib at ${lib.root}`);
|
||||||
|
} else {
|
||||||
|
parts.push("stdlib missing (no lib/ next to binary / MARQDO_LIB)");
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
cliOk: true,
|
||||||
|
libOk: lib.ok,
|
||||||
|
versionOk,
|
||||||
|
version: probe.version,
|
||||||
|
parsedVersion: parsed,
|
||||||
|
requiredVersion: need,
|
||||||
|
cliPath,
|
||||||
|
libRoot: lib.root,
|
||||||
|
detail: parts.join("; "),
|
||||||
|
suggestedMode,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function rustTargetTriple(): string | undefined {
|
||||||
|
const { platform, arch } = process;
|
||||||
|
if (platform === "win32" && arch === "x64") {
|
||||||
|
return "x86_64-pc-windows-msvc";
|
||||||
|
}
|
||||||
|
if (platform === "linux" && arch === "x64") {
|
||||||
|
return "x86_64-unknown-linux-gnu";
|
||||||
|
}
|
||||||
|
if (platform === "darwin" && arch === "arm64") {
|
||||||
|
return "aarch64-apple-darwin";
|
||||||
|
}
|
||||||
|
if (platform === "darwin" && arch === "x64") {
|
||||||
|
return "x86_64-apple-darwin";
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchLatestRelease(): Promise<GhRelease> {
|
||||||
|
const res = await fetch(`https://api.github.com/repos/${REPO}/releases/latest`, {
|
||||||
|
headers: {
|
||||||
|
Accept: "application/vnd.github+json",
|
||||||
|
"User-Agent": "marqdo-vscode-extension",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(`GitHub releases/latest HTTP ${res.status}`);
|
||||||
|
}
|
||||||
|
return (await res.json()) as GhRelease;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function downloadToFile(url: string, dest: string, onProgress?: (msg: string) => void): Promise<void> {
|
||||||
|
onProgress?.(`Downloading ${path.basename(dest)}…`);
|
||||||
|
const res = await fetch(url, {
|
||||||
|
headers: { "User-Agent": "marqdo-vscode-extension", Accept: "application/octet-stream" },
|
||||||
|
redirect: "follow",
|
||||||
|
});
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(`Download failed HTTP ${res.status}: ${url}`);
|
||||||
|
}
|
||||||
|
const buf = Buffer.from(await res.arrayBuffer());
|
||||||
|
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
||||||
|
fs.writeFileSync(dest, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
function extractZip(zipPath: string, destDir: string): void {
|
||||||
|
fs.mkdirSync(destDir, { recursive: true });
|
||||||
|
if (process.platform === "win32") {
|
||||||
|
const ps = `Expand-Archive -LiteralPath '${zipPath.replace(/'/g, "''")}' -DestinationPath '${destDir.replace(/'/g, "''")}' -Force`;
|
||||||
|
const r = spawnSync("powershell", ["-NoProfile", "-Command", ps], { encoding: "utf8" });
|
||||||
|
if (r.status !== 0) {
|
||||||
|
throw new Error(r.stderr || r.stdout || `Expand-Archive exit ${r.status}`);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const r = spawnSync("unzip", ["-o", zipPath, "-d", destDir], { encoding: "utf8" });
|
||||||
|
if (r.status !== 0) {
|
||||||
|
throw new Error(r.stderr || r.stdout || `unzip exit ${r.status}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function pickBundleAsset(release: GhRelease, triple: string): GhAsset | undefined {
|
||||||
|
const zipName = `marqdo-${release.tag_name.replace(/^v/, "")}-${triple}.zip`;
|
||||||
|
return (
|
||||||
|
release.assets.find((a) => a.name === zipName) ||
|
||||||
|
release.assets.find(
|
||||||
|
(a) => a.name.endsWith(`-${triple}.zip`) && !a.name.includes("stdlib")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function pickStdlibAsset(release: GhRelease): GhAsset | undefined {
|
||||||
|
return release.assets.find((a) => a.name.includes("stdlib") && a.name.endsWith(".zip"));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function applyManagedPaths(context: vscode.ExtensionContext, exe: string): Promise<void> {
|
||||||
|
await cfg().update("cliPath", exe, vscode.ConfigurationTarget.Global);
|
||||||
|
await cfg().update("managedCliPath", exe, vscode.ConfigurationTarget.Global);
|
||||||
|
await cfg().update("libPath", managedLibRoot(context), vscode.ConfigurationTarget.Global);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download recommended release bundle (exe + lib/) into extension globalStorage.
|
||||||
|
*/
|
||||||
|
export async function installFromGitHub(
|
||||||
|
context: vscode.ExtensionContext,
|
||||||
|
output: vscode.OutputChannel,
|
||||||
|
mode: "bundle" | "stdlib" = "bundle"
|
||||||
|
): Promise<InstallStatus> {
|
||||||
|
const triple = rustTargetTriple();
|
||||||
|
output.show(true);
|
||||||
|
|
||||||
|
return vscode.window.withProgress(
|
||||||
|
{
|
||||||
|
location: vscode.ProgressLocation.Notification,
|
||||||
|
title: "Marqdo",
|
||||||
|
cancellable: false,
|
||||||
|
},
|
||||||
|
async (progress) => {
|
||||||
|
progress.report({ message: "Fetching latest release…" });
|
||||||
|
output.appendLine(`Fetching https://github.com/${REPO}/releases/latest`);
|
||||||
|
const release = await fetchLatestRelease();
|
||||||
|
output.appendLine(`Latest: ${release.tag_name}`);
|
||||||
|
|
||||||
|
const destRoot = managedRoot(context);
|
||||||
|
fs.mkdirSync(destRoot, { recursive: true });
|
||||||
|
const tmp = path.join(os.tmpdir(), `marqdo-ext-${Date.now()}`);
|
||||||
|
fs.mkdirSync(tmp, { recursive: true });
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (mode === "bundle") {
|
||||||
|
if (!triple) {
|
||||||
|
throw new Error(
|
||||||
|
`No prebuilt bundle for ${process.platform}/${process.arch}. Open ${release.html_url} or build from source.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const asset = pickBundleAsset(release, triple);
|
||||||
|
if (!asset) {
|
||||||
|
throw new Error(
|
||||||
|
`No asset for ${triple} in ${release.tag_name}. Available: ${release.assets
|
||||||
|
.map((a) => a.name)
|
||||||
|
.join(", ") || "(none)"}. See ${release.html_url}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const zipPath = path.join(tmp, asset.name);
|
||||||
|
progress.report({ message: `Downloading ${asset.name}…` });
|
||||||
|
await downloadToFile(asset.browser_download_url, zipPath, (m) => output.appendLine(m));
|
||||||
|
progress.report({ message: "Extracting (CLI + stdlib)…" });
|
||||||
|
// Clear previous managed install
|
||||||
|
fs.rmSync(destRoot, { recursive: true, force: true });
|
||||||
|
fs.mkdirSync(destRoot, { recursive: true });
|
||||||
|
extractZip(zipPath, destRoot);
|
||||||
|
output.appendLine(`Extracted to ${destRoot}`);
|
||||||
|
} else {
|
||||||
|
const asset = pickStdlibAsset(release);
|
||||||
|
if (!asset) {
|
||||||
|
throw new Error(`No stdlib zip in ${release.tag_name}. See ${release.html_url}`);
|
||||||
|
}
|
||||||
|
const zipPath = path.join(tmp, asset.name);
|
||||||
|
progress.report({ message: `Downloading ${asset.name}…` });
|
||||||
|
await downloadToFile(asset.browser_download_url, zipPath, (m) => output.appendLine(m));
|
||||||
|
progress.report({ message: "Extracting stdlib…" });
|
||||||
|
extractZip(zipPath, destRoot);
|
||||||
|
output.appendLine(`Stdlib extracted to ${destRoot}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const exe = managedExePath(context);
|
||||||
|
if (mode === "bundle" && !fs.existsSync(exe)) {
|
||||||
|
// Some zips might nest a folder
|
||||||
|
const nested = findFileRecursive(destRoot, process.platform === "win32" ? "marqdo.exe" : "marqdo");
|
||||||
|
if (nested) {
|
||||||
|
// Flatten: move exe+lib up if needed is complex; just point cliPath at nested
|
||||||
|
await cfg().update("cliPath", nested, vscode.ConfigurationTarget.Global);
|
||||||
|
await cfg().update("managedCliPath", nested, vscode.ConfigurationTarget.Global);
|
||||||
|
const libCandidate = path.dirname(nested);
|
||||||
|
await cfg().update("libPath", libCandidate, vscode.ConfigurationTarget.Global);
|
||||||
|
} else {
|
||||||
|
throw new Error(`Extracted archive but ${exe} not found`);
|
||||||
|
}
|
||||||
|
} else if (mode === "bundle") {
|
||||||
|
await applyManagedPaths(context, exe);
|
||||||
|
} else {
|
||||||
|
await cfg().update("libPath", managedLibRoot(context), vscode.ConfigurationTarget.Global);
|
||||||
|
}
|
||||||
|
|
||||||
|
// chmod +x on unix
|
||||||
|
if (process.platform !== "win32" && fs.existsSync(exe)) {
|
||||||
|
fs.chmodSync(exe, 0o755);
|
||||||
|
}
|
||||||
|
|
||||||
|
const status = checkInstallStatus(context);
|
||||||
|
output.appendLine(status.detail);
|
||||||
|
if (status.cliOk && status.versionOk && status.libOk) {
|
||||||
|
void vscode.window.showInformationMessage(
|
||||||
|
`Marqdo ready (${status.parsedVersion ?? status.version}). Stdlib OK.`
|
||||||
|
);
|
||||||
|
} else if (status.cliOk && !status.versionOk) {
|
||||||
|
void vscode.window.showWarningMessage(
|
||||||
|
`Marqdo CLI still below ${status.requiredVersion}. ${status.detail}`
|
||||||
|
);
|
||||||
|
} else if (status.cliOk && !status.libOk) {
|
||||||
|
void vscode.window.showWarningMessage(
|
||||||
|
`Marqdo CLI ok but stdlib still missing. Try “Marqdo: Install / Repair CLI”.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
} finally {
|
||||||
|
fs.rmSync(tmp, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function findFileRecursive(root: string, name: string): string | undefined {
|
||||||
|
const stack = [root];
|
||||||
|
while (stack.length) {
|
||||||
|
const dir = stack.pop()!;
|
||||||
|
let entries: fs.Dirent[];
|
||||||
|
try {
|
||||||
|
entries = fs.readdirSync(dir, { withFileTypes: true });
|
||||||
|
} catch {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (const e of entries) {
|
||||||
|
const p = path.join(dir, e.name);
|
||||||
|
if (e.isDirectory()) {
|
||||||
|
stack.push(p);
|
||||||
|
} else if (e.name === name) {
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function promptIfNeeded(
|
||||||
|
context: vscode.ExtensionContext,
|
||||||
|
output: vscode.OutputChannel
|
||||||
|
): Promise<void> {
|
||||||
|
if (cfg().get<boolean>("autoInstall.checkOnStartup") === false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (context.globalState.get<boolean>(SKIP_KEY)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const status = checkInstallStatus(context);
|
||||||
|
output.appendLine(`[install] ${status.detail}`);
|
||||||
|
|
||||||
|
if (status.cliOk && status.versionOk && status.libOk) {
|
||||||
|
output.appendLine(`[install] ready (CLI ≥ ${status.requiredVersion}, stdlib present)`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let message: string;
|
||||||
|
let primary: string;
|
||||||
|
const mode = status.suggestedMode ?? "bundle";
|
||||||
|
|
||||||
|
if (!status.cliOk) {
|
||||||
|
message = `Marqdo CLI not detected. Install CLI ≥ ${status.requiredVersion} with the standard library?`;
|
||||||
|
primary = "Install CLI + stdlib";
|
||||||
|
} else if (!status.versionOk) {
|
||||||
|
message = `Marqdo CLI version is too old (need ≥ ${status.requiredVersion}${
|
||||||
|
status.parsedVersion ? `, found ${status.parsedVersion}` : `, raw: ${status.version}`
|
||||||
|
}). Upgrade now (includes stdlib)?`;
|
||||||
|
primary = "Upgrade CLI + stdlib";
|
||||||
|
} else {
|
||||||
|
message =
|
||||||
|
"Marqdo CLI is OK, but the standard library (lib/) is missing. Download stdlib into the extension?";
|
||||||
|
primary = "Install stdlib";
|
||||||
|
}
|
||||||
|
|
||||||
|
const choice = await vscode.window.showWarningMessage(
|
||||||
|
message,
|
||||||
|
{ modal: false },
|
||||||
|
primary,
|
||||||
|
"Open Releases",
|
||||||
|
"Don't ask again"
|
||||||
|
);
|
||||||
|
|
||||||
|
if (choice === primary) {
|
||||||
|
try {
|
||||||
|
await installFromGitHub(context, output, mode);
|
||||||
|
} catch (e) {
|
||||||
|
const err = e instanceof Error ? e.message : String(e);
|
||||||
|
output.appendLine(`[install] ${err}`);
|
||||||
|
const open = await vscode.window.showErrorMessage(`Marqdo install failed: ${err}`, "Open Releases");
|
||||||
|
if (open) {
|
||||||
|
await vscode.env.openExternal(vscode.Uri.parse(`https://github.com/${REPO}/releases`));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (choice === "Open Releases") {
|
||||||
|
await vscode.env.openExternal(vscode.Uri.parse(`https://github.com/${REPO}/releases`));
|
||||||
|
} else if (choice === "Don't ask again") {
|
||||||
|
await context.globalState.update(SKIP_KEY, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function resetSkipPrompt(context: vscode.ExtensionContext): Promise<void> {
|
||||||
|
await context.globalState.update(SKIP_KEY, undefined);
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
import * as vscode from "vscode";
|
||||||
|
import { compareSemver, parseCliVersion } from "./install";
|
||||||
|
|
||||||
|
const REPO = "cflmy/marqdo";
|
||||||
|
const LAST_CHECK_KEY = "marqdo.lastUpdateCheck";
|
||||||
|
const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
||||||
|
|
||||||
|
type GhRelease = {
|
||||||
|
tag_name: string;
|
||||||
|
html_url: string;
|
||||||
|
assets: { name: string }[];
|
||||||
|
};
|
||||||
|
|
||||||
|
async function fetchLatestRelease(): Promise<GhRelease> {
|
||||||
|
const res = await fetch(`https://api.github.com/repos/${REPO}/releases/latest`, {
|
||||||
|
headers: {
|
||||||
|
Accept: "application/vnd.github+json",
|
||||||
|
"User-Agent": "marqdo-vscode-extension",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(`GitHub releases/latest HTTP ${res.status}`);
|
||||||
|
}
|
||||||
|
return (await res.json()) as GhRelease;
|
||||||
|
}
|
||||||
|
|
||||||
|
function extensionVersion(): string {
|
||||||
|
return vscode.extensions.getExtension("cflmy.marqdo")?.packageJSON?.version ?? "0.0.0";
|
||||||
|
}
|
||||||
|
|
||||||
|
function pickVsixAsset(release: GhRelease): string | undefined {
|
||||||
|
const mine = extensionVersion();
|
||||||
|
const exact = release.assets.find((a) => a.name === `marqdo-${mine}.vsix`);
|
||||||
|
if (exact) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return release.assets.find((a) => a.name.endsWith(".vsix"))?.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Notify when a newer CLI or extension release exists on GitHub. */
|
||||||
|
export async function checkForUpdates(
|
||||||
|
context: vscode.ExtensionContext,
|
||||||
|
output: vscode.OutputChannel,
|
||||||
|
installedCliVersion?: string
|
||||||
|
): Promise<void> {
|
||||||
|
if (vscode.workspace.getConfiguration("marqdo").get<boolean>("autoInstall.checkUpdates") === false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const last = context.globalState.get<number>(LAST_CHECK_KEY) ?? 0;
|
||||||
|
if (Date.now() - last < CHECK_INTERVAL_MS) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await context.globalState.update(LAST_CHECK_KEY, Date.now());
|
||||||
|
|
||||||
|
try {
|
||||||
|
const release = await fetchLatestRelease();
|
||||||
|
const latestTag = release.tag_name.replace(/^v/, "");
|
||||||
|
const extVer = extensionVersion();
|
||||||
|
const messages: string[] = [];
|
||||||
|
|
||||||
|
if (compareSemver(latestTag, extVer) > 0 || pickVsixAsset(release)) {
|
||||||
|
messages.push(`extension ${extVer} → ${release.tag_name}`);
|
||||||
|
}
|
||||||
|
const parsedCli = installedCliVersion ? parseCliVersion(installedCliVersion) : undefined;
|
||||||
|
if (parsedCli && compareSemver(latestTag, parsedCli) > 0) {
|
||||||
|
messages.push(`CLI ${parsedCli} → ${release.tag_name}`);
|
||||||
|
}
|
||||||
|
if (messages.length === 0) {
|
||||||
|
output.appendLine(`[update] up to date (${release.tag_name})`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
output.appendLine(`[update] newer release: ${messages.join("; ")}`);
|
||||||
|
const choice = await vscode.window.showInformationMessage(
|
||||||
|
`Marqdo ${release.tag_name} is available (${messages.join(", ")}).`,
|
||||||
|
"Open Releases",
|
||||||
|
"Later"
|
||||||
|
);
|
||||||
|
if (choice === "Open Releases") {
|
||||||
|
await vscode.env.openExternal(vscode.Uri.parse(release.html_url));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
output.appendLine(
|
||||||
|
`[update] check skipped: ${e instanceof Error ? e.message : String(e)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,182 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
|
||||||
|
"name": "Marqdo",
|
||||||
|
"scopeName": "source.marqdo",
|
||||||
|
"patterns": [
|
||||||
|
{ "include": "#frontmatter" },
|
||||||
|
{ "include": "#code-fence" },
|
||||||
|
{ "include": "#formula" },
|
||||||
|
{ "include": "#heading" },
|
||||||
|
{ "include": "#empty-return" },
|
||||||
|
{ "include": "#hr-end" },
|
||||||
|
{ "include": "#call" },
|
||||||
|
{ "include": "#else-arm" },
|
||||||
|
{ "include": "#return-line" },
|
||||||
|
{ "include": "#statement-line" },
|
||||||
|
{ "include": "#param-line" },
|
||||||
|
{ "include": "#loop-line" },
|
||||||
|
{ "include": "#branch" },
|
||||||
|
{ "include": "#table" },
|
||||||
|
{ "include": "#inline-code" },
|
||||||
|
{ "include": "#comment" }
|
||||||
|
],
|
||||||
|
"repository": {
|
||||||
|
"frontmatter": {
|
||||||
|
"name": "meta.embedded.block.frontmatter.marqdo",
|
||||||
|
"begin": "\\A---\\s*$",
|
||||||
|
"end": "^---\\s*$",
|
||||||
|
"beginCaptures": {
|
||||||
|
"0": { "name": "punctuation.definition.frontmatter.begin.marqdo" }
|
||||||
|
},
|
||||||
|
"endCaptures": {
|
||||||
|
"0": { "name": "punctuation.definition.frontmatter.end.marqdo" }
|
||||||
|
},
|
||||||
|
"patterns": [
|
||||||
|
{
|
||||||
|
"name": "meta.import.marqdo",
|
||||||
|
"match": "^(\\s*)(>)(\\s+)(\\S.*)$",
|
||||||
|
"captures": {
|
||||||
|
"2": { "name": "keyword.control.import.marqdo" },
|
||||||
|
"4": { "name": "string.unquoted.import.path.marqdo" }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "meta.frontmatter.field.marqdo",
|
||||||
|
"match": "^([A-Za-z0-9_-]+)\\s*:\\s*(.*)$",
|
||||||
|
"captures": {
|
||||||
|
"1": { "name": "entity.name.tag.frontmatter.marqdo" },
|
||||||
|
"2": { "name": "string.unquoted.frontmatter.marqdo" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"heading": {
|
||||||
|
"name": "markup.heading.marqdo",
|
||||||
|
"match": "^(#{1,6})(\\s+)(.+)$",
|
||||||
|
"captures": {
|
||||||
|
"1": { "name": "punctuation.definition.heading.marqdo" },
|
||||||
|
"3": { "name": "entity.name.function.marqdo" }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"empty-return": {
|
||||||
|
"name": "keyword.control.return.empty.marqdo",
|
||||||
|
"match": "^\\s*(\\*{4}|\\*\\*\\s+\\*\\*)\\s*$"
|
||||||
|
},
|
||||||
|
"hr-end": {
|
||||||
|
"name": "keyword.control.function.end.marqdo",
|
||||||
|
"match": "^\\s*(---+|\\*{3})\\s*$"
|
||||||
|
},
|
||||||
|
"call": {
|
||||||
|
"name": "meta.call.marqdo",
|
||||||
|
"match": "^(\\s*)(>)(\\s+)(\\S+)(.*)$",
|
||||||
|
"captures": {
|
||||||
|
"2": { "name": "keyword.operator.call.marqdo" },
|
||||||
|
"4": { "name": "entity.name.function.call.marqdo" },
|
||||||
|
"5": { "name": "meta.call.args.marqdo" }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"else-arm": {
|
||||||
|
"name": "keyword.control.conditional.else.marqdo",
|
||||||
|
"match": "^(\\s*)(\\*)(\\s*)$"
|
||||||
|
},
|
||||||
|
"return-line": {
|
||||||
|
"name": "meta.return.marqdo",
|
||||||
|
"begin": "^(\\s*)(\\*\\*)(?!\\*)",
|
||||||
|
"beginCaptures": {
|
||||||
|
"2": { "name": "punctuation.definition.return.begin.marqdo" }
|
||||||
|
},
|
||||||
|
"end": "(\\*\\*)",
|
||||||
|
"endCaptures": {
|
||||||
|
"1": { "name": "punctuation.definition.return.end.marqdo" }
|
||||||
|
},
|
||||||
|
"contentName": "markup.bold.return.marqdo",
|
||||||
|
"patterns": [
|
||||||
|
{ "include": "#inline-code" },
|
||||||
|
{ "include": "#call-inline" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"statement-line": {
|
||||||
|
"name": "meta.statement.marqdo",
|
||||||
|
"begin": "^(\\s*)(\\*)(?!\\*)",
|
||||||
|
"beginCaptures": {
|
||||||
|
"2": { "name": "punctuation.definition.statement.begin.marqdo" }
|
||||||
|
},
|
||||||
|
"end": "(?<!\\*)(\\*)(?!\\*)\\s*$",
|
||||||
|
"endCaptures": {
|
||||||
|
"1": { "name": "punctuation.definition.statement.end.marqdo" }
|
||||||
|
},
|
||||||
|
"contentName": "markup.italic.statement.marqdo",
|
||||||
|
"patterns": [
|
||||||
|
{ "include": "#inline-code" },
|
||||||
|
{ "include": "#call-inline" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"call-inline": {
|
||||||
|
"name": "meta.call.inline.marqdo",
|
||||||
|
"match": "(>)(\\s*)(\\S+)",
|
||||||
|
"captures": {
|
||||||
|
"1": { "name": "keyword.operator.call.marqdo" },
|
||||||
|
"3": { "name": "entity.name.function.call.marqdo" }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"param-line": {
|
||||||
|
"name": "meta.param.marqdo",
|
||||||
|
"match": "^(\\s*)(\\+)(\\s+)(.+)$",
|
||||||
|
"captures": {
|
||||||
|
"2": { "name": "keyword.other.param.marqdo" },
|
||||||
|
"4": { "name": "variable.parameter.marqdo" }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"loop-line": {
|
||||||
|
"name": "meta.loop.marqdo",
|
||||||
|
"match": "^(\\s*)(-)(\\s+)(.+)$",
|
||||||
|
"captures": {
|
||||||
|
"2": { "name": "keyword.control.loop.marqdo" },
|
||||||
|
"4": { "name": "meta.loop.body.marqdo" }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"branch": {
|
||||||
|
"name": "meta.branch.marqdo",
|
||||||
|
"match": "^(\\s*)(\\d+\\.)(\\s+)(.*)$",
|
||||||
|
"captures": {
|
||||||
|
"2": { "name": "keyword.control.conditional.marqdo" },
|
||||||
|
"4": { "name": "meta.branch.condition.marqdo" }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"table": {
|
||||||
|
"name": "markup.table.marqdo",
|
||||||
|
"match": "^\\s*\\|.*\\|\\s*$"
|
||||||
|
},
|
||||||
|
"formula": {
|
||||||
|
"name": "meta.embedded.math.marqdo",
|
||||||
|
"begin": "^\\s*\\$\\$\\s*$",
|
||||||
|
"end": "^\\s*\\$\\$\\s*$",
|
||||||
|
"contentName": "string.other.math.marqdo"
|
||||||
|
},
|
||||||
|
"code-fence": {
|
||||||
|
"name": "markup.fenced_code.block.marqdo",
|
||||||
|
"begin": "^(\\s*)(```)([\\w+-]*)\\s*$",
|
||||||
|
"beginCaptures": {
|
||||||
|
"2": { "name": "punctuation.definition.raw.begin.marqdo" },
|
||||||
|
"3": { "name": "entity.name.tag.lang.marqdo" }
|
||||||
|
},
|
||||||
|
"end": "^(\\s*)(```)\\s*$",
|
||||||
|
"endCaptures": {
|
||||||
|
"2": { "name": "punctuation.definition.raw.end.marqdo" }
|
||||||
|
},
|
||||||
|
"contentName": "markup.raw.block.marqdo"
|
||||||
|
},
|
||||||
|
"inline-code": {
|
||||||
|
"name": "string.interpolated.marqdo",
|
||||||
|
"match": "`([^`]+)`",
|
||||||
|
"captures": {
|
||||||
|
"0": { "name": "markup.inline.raw.marqdo" },
|
||||||
|
"1": { "name": "variable.other.marqdo" }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"comment": {
|
||||||
|
"name": "comment.line.marqdo",
|
||||||
|
"match": "^.+$"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "commonjs",
|
||||||
|
"target": "ES2020",
|
||||||
|
"outDir": "out",
|
||||||
|
"rootDir": "src",
|
||||||
|
"lib": ["ES2020"],
|
||||||
|
"sourceMap": true,
|
||||||
|
"strict": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"skipLibCheck": true
|
||||||
|
},
|
||||||
|
"exclude": ["node_modules", ".vscode-test"]
|
||||||
|
}
|
||||||
Reference in new issue
Block a user