dsh-vscode-mode 0.1.51 → 0.1.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -8189,8 +8189,16 @@ async function extractTo(buf, dir) {
8189
8189
  }
8190
8190
  //#endregion
8191
8191
  //#region src/lsp/config.ts
8192
- const LSP_SETTINGS_NS = "dsh-vscode-mode.languageServers";
8192
+ /**
8193
+ * dsh-vscode-mode host — LSP 配置读取与 provider 解析装配。
8194
+ * 配置来源优先级:运行时覆盖(设置页保存,重启失效)> 插件组合配置 > 默认。
8195
+ * 原 settings section(ns dsh-vscode-mode.languageServers)命名空间不合法
8196
+ * (DSH settings 仅允许 /^[a-z][a-z0-9-]*$/,点号命名空间永久不可注册),
8197
+ * 已降级为配置值(插件组合配置 + 会话内运行时覆盖),不再尝试 settings 安装。
8198
+ * 作者 ddj 2026-08-27 / 2026-09-02
8199
+ */
8193
8200
  const LSP_LANGUAGES = ["lua", "csharp"];
8201
+ /** 清洗单语言配置:仅保留合法字段并剥离 undefined(稀疏覆盖语义,清空字段即回落组合配置)。 */
8194
8202
  function sanitizeLang(raw) {
8195
8203
  if (!raw || typeof raw !== "object") return void 0;
8196
8204
  const obj = raw;
@@ -8211,22 +8219,7 @@ function configFromPlugin(config) {
8211
8219
  }
8212
8220
  return out;
8213
8221
  }
8214
- /** settings 描述符读取(无 settings 服务/无该 section → {})。 */
8215
- function configFromSettings(ctx) {
8216
- try {
8217
- const value = (ctx.get("settings")?.describe?.({ redactSecrets: true })?.find((item) => item.ns === LSP_SETTINGS_NS))?.value;
8218
- if (!value || typeof value !== "object") return {};
8219
- const out = {};
8220
- for (const lang of LSP_LANGUAGES) {
8221
- const v = sanitizeLang(value[lang]);
8222
- if (v) out[lang] = v;
8223
- }
8224
- return out;
8225
- } catch (error) {
8226
- return {};
8227
- }
8228
- }
8229
- /** 合并配置:settings 覆盖插件配置。 */
8222
+ /** 合并配置:上层(运行时覆盖/settings)覆盖插件组合配置。 */
8230
8223
  function mergeConfig(a, b) {
8231
8224
  const out = { ...a };
8232
8225
  for (const lang of LSP_LANGUAGES) {
@@ -8241,14 +8234,14 @@ function mergeConfig(a, b) {
8241
8234
  return out;
8242
8235
  }
8243
8236
  /**
8244
- * 解析某语言的 provider spec(合并配置后)。
8245
- * @author ddj 2026年08月27号
8246
- * @param ctx DSH 上下文
8237
+ * 解析某语言的 provider spec(插件组合配置 + 运行时覆盖层合并后)。
8238
+ * @author ddj 2026年08月27号 / 2026年09月02号
8247
8239
  * @param pluginConfig 插件组合配置
8248
8240
  * @param languageId 语言 id
8241
+ * @param override 运行时覆盖层(设置页保存值,重启失效;缺省为空)
8249
8242
  * @returns provider 规格
8250
8243
  */
8251
- function resolveProviderSpec(ctx, pluginConfig, languageId) {
8244
+ function resolveProviderSpec(pluginConfig, languageId, override) {
8252
8245
  const resolver = PROVIDER_RESOLVERS[languageId];
8253
8246
  if (!resolver) return {
8254
8247
  languageId,
@@ -8257,7 +8250,7 @@ function resolveProviderSpec(ctx, pluginConfig, languageId) {
8257
8250
  ready: false,
8258
8251
  reason: "不支持的语言:" + languageId
8259
8252
  };
8260
- const lang = mergeConfig(configFromPlugin(pluginConfig), configFromSettings(ctx))[languageId];
8253
+ const lang = mergeConfig(configFromPlugin(pluginConfig), override ?? {})[languageId];
8261
8254
  if (lang && lang.enabled === false) return {
8262
8255
  languageId,
8263
8256
  kind: "none",
@@ -8455,6 +8448,8 @@ function createDocTracker() {
8455
8448
  function createLspRpc(deps) {
8456
8449
  const { ctx, pluginConfig, manager } = deps;
8457
8450
  const tracker = createDocTracker();
8451
+ /** 运行时覆盖层:设置页保存值(内存态,重启回落组合配置值;每 apply 新建,插件重载自动复位)。 */
8452
+ const runtimeConfig = {};
8458
8453
  onRuntimeProvisioned(() => {
8459
8454
  clearProviderCache();
8460
8455
  manager.resetLanguage("csharp");
@@ -8473,7 +8468,7 @@ function createLspRpc(deps) {
8473
8468
  return { err: String(error) };
8474
8469
  }
8475
8470
  };
8476
- const acquireServer = (root, lang) => manager.acquire(root, lang, (languageId) => resolveProviderSpec(ctx, pluginConfig, languageId));
8471
+ const acquireServer = (root, lang) => manager.acquire(root, lang, (languageId) => resolveProviderSpec(pluginConfig, languageId, runtimeConfig));
8477
8472
  const serverOf = (root, lang) => manager.peek(root, lang);
8478
8473
  const rootLocations = (locations, root) => locations.map((location) => ({
8479
8474
  ...location,
@@ -8481,7 +8476,7 @@ function createLspRpc(deps) {
8481
8476
  }));
8482
8477
  /** 当前 provider 检测结论 → 设置页 idle 状态(不启动 server);附带未满足的环境需求与候选服务器。 */
8483
8478
  const detectedStatus = (languageId, root) => {
8484
- const spec = resolveProviderSpec(ctx, pluginConfig, languageId);
8479
+ const spec = resolveProviderSpec(pluginConfig, languageId, runtimeConfig);
8485
8480
  const missingEnv = envRequirementsFor(languageId, dshHome());
8486
8481
  const candidates = candidatesFor(languageId, spec);
8487
8482
  return {
@@ -8546,16 +8541,9 @@ function createLspRpc(deps) {
8546
8541
  };
8547
8542
  },
8548
8543
  "edrv.lsp.configGet": async () => {
8549
- const settings = configFromSettings(ctx);
8550
- const plugin = configFromPlugin(pluginConfig);
8551
- const merged = { ...plugin };
8552
- for (const lang of Object.keys(settings)) merged[lang] = {
8553
- ...plugin[lang],
8554
- ...settings[lang]
8555
- };
8556
8544
  return {
8557
8545
  ok: true,
8558
- config: merged
8546
+ config: mergeConfig(configFromPlugin(pluginConfig), runtimeConfig)
8559
8547
  };
8560
8548
  },
8561
8549
  "edrv.lsp.configUpdate": async (args) => {
@@ -8564,29 +8552,16 @@ function createLspRpc(deps) {
8564
8552
  ok: false,
8565
8553
  error: "不支持的语言:" + lang
8566
8554
  };
8567
- const current = configFromSettings(ctx);
8568
- const target = {
8569
- ...current,
8570
- [lang]: { ...current[lang] ?? {} }
8571
- }[lang];
8555
+ const target = { ...runtimeConfig[lang] ?? {} };
8572
8556
  if (args.enabled !== void 0) target.enabled = args.enabled;
8573
8557
  if (args.command !== void 0) target.command = args.command || void 0;
8574
8558
  if (args.path !== void 0) target.path = args.path || void 0;
8559
+ runtimeConfig[lang] = sanitizeLang(target) ?? {};
8575
8560
  try {
8576
- const settings = ctx.get("settings");
8577
- if (!settings?.update) return {
8578
- ok: false,
8579
- error: "设置服务不可用"
8580
- };
8581
- await settings.update(LSP_SETTINGS_NS, { [lang]: target });
8582
8561
  const servers = await redetectLanguage(lang);
8583
- const stored = (settings.describe?.({ redactSecrets: true })?.find((item) => item.ns === LSP_SETTINGS_NS))?.value;
8584
8562
  return {
8585
8563
  ok: true,
8586
- config: {
8587
- ...configFromPlugin(pluginConfig),
8588
- ...stored
8589
- },
8564
+ config: mergeConfig(configFromPlugin(pluginConfig), runtimeConfig),
8590
8565
  servers
8591
8566
  };
8592
8567
  } catch (error) {
@@ -8926,40 +8901,6 @@ function createLspRpc(deps) {
8926
8901
  };
8927
8902
  }
8928
8903
  //#endregion
8929
- //#region src/lsp/settings.ts
8930
- /**
8931
- * 安装 LSP 设置 section。
8932
- * @author ddj 2026年08月27号
8933
- * @param ctx DSH 上下文
8934
- * @param entry 初始配置
8935
- * @returns 是否成功安装
8936
- */
8937
- async function installLspSettingsSection(ctx, entry) {
8938
- let deps = null;
8939
- try {
8940
- deps = await loadSettingsDeps();
8941
- } catch {}
8942
- if (!deps) return false;
8943
- try {
8944
- const z = deps.z;
8945
- const langShape = {};
8946
- for (const lang of LSP_LANGUAGES) langShape[lang] = z.object({
8947
- enabled: z.boolean(),
8948
- command: z.string(),
8949
- path: z.string()
8950
- }).default({});
8951
- const schema = z.object(langShape).default({});
8952
- const strategy = await runSettingsInstall(ctx, LSP_SETTINGS_NS, schema, entry, {
8953
- setSource: () => {},
8954
- onChange: () => {}
8955
- });
8956
- return strategy === "legacy" || strategy === "service";
8957
- } catch (error) {
8958
- console.error("[dsh-vscode-mode] LSP 设置 section 安装失败:" + String(error));
8959
- return false;
8960
- }
8961
- }
8962
- //#endregion
8963
8904
  //#region src/index.ts
8964
8905
  /**
8965
8906
  * @dsh-external 生态 → dsh-vscode-mode:DSH 上的类 VSCode 编码体验(Host 半入口)。
@@ -8994,7 +8935,7 @@ function apply(ctx, config) {
8994
8935
  /** 兼容性警告收集(route 护栏等写入,启动日志一并输出)。 */
8995
8936
  const warnings = [];
8996
8937
  setupOpenSettings(ctx, config, () => {});
8997
- installLspSettingsSection(ctx, {});
8938
+ /** LSP 配置为配置值模式:插件组合配置 + 会话内运行时覆盖(原 settings section 命名空间不合法,见 lsp/config.ts)。 */
8998
8939
  /** 规则注入 section(~/.dsh/rules 与 <工作区>/.dsh/rules;旧版 DSH 无 systemPrompt 时静默降级)。 */
8999
8940
  const rulesInstalled = installRulesSection(ctx);
9000
8941
  if (!rulesInstalled) ctx.logger?.warn?.("[" + name + "] 未检测到 systemPrompt 服务,规则仅可管理不注入");