codemode-lsp 0.1.1 → 0.1.2

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.
Files changed (2) hide show
  1. package/dist/index.js +56 -26
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -46102,6 +46102,25 @@ function buildTracedLsp(api2, trace, makeSandboxError, wrapAsync, opNames) {
46102
46102
  return traced;
46103
46103
  }
46104
46104
  var hostPath = { join: join2, basename, dirname: dirname4, extname };
46105
+ var UNCAPTURED_STATEMENT_NAMES = {
46106
+ IfStatement: "an if statement",
46107
+ ForStatement: "a for loop",
46108
+ ForOfStatement: "a for...of loop",
46109
+ ForInStatement: "a for...in loop",
46110
+ WhileStatement: "a while loop",
46111
+ DoWhileStatement: "a do...while loop",
46112
+ TryStatement: "a try/catch block",
46113
+ SwitchStatement: "a switch statement",
46114
+ BlockStatement: "a block",
46115
+ VariableDeclaration: "a variable declaration",
46116
+ FunctionDeclaration: "a function declaration",
46117
+ ClassDeclaration: "a class declaration"
46118
+ };
46119
+ function describeUncapturedStatement(type) {
46120
+ if (type === "ReturnStatement")
46121
+ return;
46122
+ return UNCAPTURED_STATEMENT_NAMES[type] ?? `a ${type}`;
46123
+ }
46105
46124
  function isExpressionStatement(node) {
46106
46125
  return node.type === "ExpressionStatement";
46107
46126
  }
@@ -46137,8 +46156,14 @@ function normalizeCode(code) {
46137
46156
  return { source: `${head}
46138
46157
  return (${expr});` };
46139
46158
  }
46140
- return { source: `${trimmed}
46141
- return undefined;` };
46159
+ return {
46160
+ source: `${trimmed}
46161
+ return undefined;`,
46162
+ ...last ? (() => {
46163
+ const described = describeUncapturedStatement(last.type);
46164
+ return described ? { uncapturedLastStatement: described } : {};
46165
+ })() : {}
46166
+ };
46142
46167
  }
46143
46168
  function capText(text, cap, marker) {
46144
46169
  if (text.length <= cap)
@@ -46249,7 +46274,7 @@ async function runSandbox(code, options) {
46249
46274
  };
46250
46275
  const opNames = options.readonly ? [...READ_OP_NAMES] : [...READ_OP_NAMES, ...WRITE_OP_NAMES];
46251
46276
  sandbox.lsp = buildTracedLsp(options.lsp, trace, makeSandboxError, wrapAsync, opNames);
46252
- const { source } = normalizeCode(code);
46277
+ const { source, uncapturedLastStatement } = normalizeCode(code);
46253
46278
  const wrapped = `(async () => {
46254
46279
  ${source}
46255
46280
  })()`;
@@ -46290,7 +46315,7 @@ ${source}
46290
46315
  }
46291
46316
  let result;
46292
46317
  try {
46293
- result = serializeResult(value);
46318
+ result = value === undefined && uncapturedLastStatement ? `undefined — note: the script's last statement is ${uncapturedLastStatement}, ` + "which produces no capturable value. Only a top-level trailing " + "expression becomes the result — end the script with a bare " + "expression (e.g. `({ count })`), or use a top-level `return`." : serializeResult(value);
46294
46319
  } catch (error51) {
46295
46320
  throw new SandboxError({
46296
46321
  error: error51 instanceof Error ? error51.message : String(error51),
@@ -46469,11 +46494,11 @@ ${LSP_WRITE_INTERFACES}`;
46469
46494
 
46470
46495
  // Write operations — buffered, applied atomically when the script succeeds.
46471
46496
  ${LSP_WRITE_OP_SIGNATURES}`;
46472
- return `${interfaces}
46473
-
46474
- declare const lsp: {
46497
+ return `declare const lsp: {
46475
46498
  ${ops}
46476
- };`;
46499
+ };
46500
+
46501
+ ${interfaces}`;
46477
46502
  }
46478
46503
  var TEMPLATE = `Execute JavaScript to perform semantic code operations via LSP (TypeScript).
46479
46504
 
@@ -46484,36 +46509,41 @@ instead of across many tool calls. The sandbox provides \`lsp\`,
46484
46509
  setTimeout). The tool returns { result, logs, changes }, where \`result\` is the
46485
46510
  script's last expression, JSON-serialized.
46486
46511
 
46487
- ## API
46488
-
46489
- {{types}}
46490
-
46491
- {{writeSemantics}}
46492
-
46493
- ## Examples
46494
-
46495
- {{examples}}
46496
-
46497
46512
  ## Rules
46498
46513
 
46499
- - The last expression is the return value — end the script with the value you
46500
- want back, e.g. \`({ count })\`.
46514
+ - The last TOP-LEVEL expression is the return value — end the script with a
46515
+ bare expression, e.g. \`({ count })\`. An expression inside a trailing
46516
+ if/for/try block is NOT captured; use a top-level \`return\` from inside
46517
+ blocks.
46501
46518
  - Every \`lsp.*\` call returns a Promise — always \`await\` it. An un-awaited
46502
46519
  call inside the result serializes as \`{}\`.
46503
46520
  - \`.filter()\`/\`.map()\` callbacks cannot be async — use \`for...of\` with \`await\`.
46504
- - Globs match the whole workspace-relative path: \`listFiles("src/**")\` for a
46505
- directory (a bare directory name like \`"src"\` is treated as \`src/**\`),
46506
- \`listFiles()\` for every file. \`searchText\`'s second argument is a glob
46507
- string there is no options object; filter results in your script.
46521
+ - \`searchText\`/\`listFiles\` cover the whole workspace (minus .gitignore);
46522
+ scope with a glob, which matches the full workspace-relative path:
46523
+ \`listFiles("src/**")\` for a directory (a bare name like \`"src"\` is treated
46524
+ as \`src/**\`), \`listFiles()\` for every file. \`searchText\`'s second argument
46525
+ is a glob string — there is no options object; filter results in your script.
46508
46526
  - Symbol paths are slash-separated (\`MyClass/myMethod\`); discover exact paths
46509
46527
  with \`getSymbols(file)\` rather than guessing. Symbol ops always take the
46510
46528
  pair \`(file, symbolPath)\` — a \`SymbolInfo.path\` belongs to the file you
46511
- called \`getSymbols\` on.
46529
+ called \`getSymbols\` on, and round-trips into findReferences/goToDefinition/
46530
+ the write ops.
46512
46531
  - \`searchText\` patterns are regexes — escape metacharacters for literal text:
46513
46532
  \`searchText("new NotFoundError\\\\(")\`.
46514
46533
  - File paths are relative to the workspace root; anything outside it is
46515
46534
  rejected.
46516
- - Diagnostics cover files touched this session only, never the whole project.`;
46535
+ - Diagnostics cover files touched this session only, never the whole project.
46536
+ \`Diagnostic.range\` is zero-based; every other line/column is 1-based.
46537
+
46538
+ ## API
46539
+
46540
+ {{types}}
46541
+
46542
+ {{writeSemantics}}
46543
+
46544
+ ## Examples
46545
+
46546
+ {{examples}}`;
46517
46547
  var WRITE_SEMANTICS = `Write operations available: writes are buffered during the script and applied
46518
46548
  atomically (flushed to disk) only when the whole script succeeds; if it throws,
46519
46549
  every buffered write is rolled back and the codebase is unchanged. The tool
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codemode-lsp",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "MCP server exposing a single code-mode tool backed by LSP",
5
5
  "keywords": [
6
6
  "mcp",