@elyracode/lsp-php 0.9.56 → 0.9.57
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/CHANGELOG.md +2 -0
- package/extensions/index.ts +104 -107
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/extensions/index.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type EditToolDetails,
|
|
3
|
-
type EditToolInput,
|
|
4
|
-
type ExtensionAPI,
|
|
5
|
-
isEditToolResult,
|
|
6
|
-
} from "@elyracode/coding-agent";
|
|
7
1
|
import { type ChildProcess, execSync, spawn } from "node:child_process";
|
|
8
2
|
import { existsSync, readFileSync } from "node:fs";
|
|
9
3
|
import { join, resolve } from "node:path";
|
|
4
|
+
import { type EditToolDetails, type EditToolInput, type ExtensionAPI, isEditToolResult } from "@elyracode/coding-agent";
|
|
10
5
|
import { Type } from "typebox";
|
|
11
6
|
|
|
12
7
|
// ── LSP Types ───────────────────────────────────────────────────────────────
|
|
@@ -434,7 +429,7 @@ export default function (elyra: ExtensionAPI): void {
|
|
|
434
429
|
const locations: LspLocation[] = Array.isArray(result) ? result : [result as LspLocation];
|
|
435
430
|
if (locations.length === 0) return "No results found.";
|
|
436
431
|
|
|
437
|
-
const prefix = workingDir
|
|
432
|
+
const prefix = `${workingDir}/`;
|
|
438
433
|
return locations
|
|
439
434
|
.map((loc) => {
|
|
440
435
|
const p = uriToPath(loc.uri);
|
|
@@ -648,117 +643,119 @@ export default function (elyra: ExtensionAPI): void {
|
|
|
648
643
|
const message = err instanceof Error ? err.message : String(err);
|
|
649
644
|
return { content: [{ type: "text", text: `Error: ${message}` }], details: {} };
|
|
650
645
|
}
|
|
651
|
-
|
|
652
|
-
|
|
646
|
+
},
|
|
647
|
+
});
|
|
653
648
|
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
649
|
+
// ── Hook: auto-context, auto-diagnostics, and blast radius on edit ──
|
|
650
|
+
elyra.on("tool_result", async (event) => {
|
|
651
|
+
if (!initialized || !isEditToolResult(event) || event.isError) return undefined;
|
|
657
652
|
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
653
|
+
const input = event.input as unknown as EditToolInput;
|
|
654
|
+
if (typeof input?.path !== "string" || !Array.isArray(input.edits)) return undefined;
|
|
655
|
+
if (!input.path.endsWith(".php")) return undefined;
|
|
661
656
|
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
657
|
+
try {
|
|
658
|
+
syncFile(input.path);
|
|
659
|
+
const absPath = resolve(cwd, input.path);
|
|
660
|
+
const fileText = readFileSync(absPath, "utf-8");
|
|
661
|
+
const details = event.details as EditToolDetails | undefined;
|
|
662
|
+
const fromLine = details?.firstChangedLine ?? 1;
|
|
663
|
+
const uri = fileUri(absPath);
|
|
664
|
+
const sections: string[] = [];
|
|
665
|
+
|
|
666
|
+
// 1. Related symbols: hover summaries for referenced types.
|
|
667
|
+
const candidates = new Set<string>();
|
|
668
|
+
for (const edit of input.edits) {
|
|
669
|
+
for (const s of extractCandidateSymbols(edit.newText, PHP_SYMBOL_STOPLIST, 4)) candidates.add(s);
|
|
670
|
+
}
|
|
671
|
+
const lookups = [...candidates].slice(0, 5).map(async (symbol) => {
|
|
672
|
+
const pos = findSymbolPosition(fileText, symbol, fromLine);
|
|
673
|
+
if (!pos) return undefined;
|
|
674
|
+
try {
|
|
675
|
+
const result = await sendRequest("textDocument/hover", {
|
|
676
|
+
textDocument: { uri },
|
|
677
|
+
position: positionFromLineCol(pos.line, pos.column),
|
|
678
|
+
});
|
|
679
|
+
const summary = summarizeHover(result);
|
|
680
|
+
return summary ? `- ${symbol}: ${summary}` : undefined;
|
|
681
|
+
} catch {
|
|
682
|
+
return undefined;
|
|
675
683
|
}
|
|
676
|
-
|
|
677
|
-
const pos = findSymbolPosition(fileText, symbol, fromLine);
|
|
678
|
-
if (!pos) return undefined;
|
|
679
|
-
try {
|
|
680
|
-
const result = await sendRequest("textDocument/hover", {
|
|
681
|
-
textDocument: { uri },
|
|
682
|
-
position: positionFromLineCol(pos.line, pos.column),
|
|
683
|
-
});
|
|
684
|
-
const summary = summarizeHover(result);
|
|
685
|
-
return summary ? `- ${symbol}: ${summary}` : undefined;
|
|
686
|
-
} catch {
|
|
687
|
-
return undefined;
|
|
688
|
-
}
|
|
689
|
-
});
|
|
684
|
+
});
|
|
690
685
|
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
}
|
|
739
|
-
})();
|
|
740
|
-
|
|
741
|
-
const [hoverLines, blast, diag] = await Promise.all([Promise.all(lookups), blastRadius, freshDiagnostics]);
|
|
742
|
-
|
|
743
|
-
const related = hoverLines.filter((l): l is string => !!l);
|
|
744
|
-
if (diag) sections.push(`[Diagnostics \u2014 auto-checked via LSP]\n${diag}`);
|
|
745
|
-
if (blast) sections.push(`[Blast radius \u2014 auto-resolved via LSP]\n${blast}`);
|
|
746
|
-
if (related.length > 0) {
|
|
747
|
-
sections.push(`[Related symbols \u2014 auto-resolved via LSP, no extra tool call needed]\n${related.join("\n")}`);
|
|
686
|
+
// 2. Blast radius: references to the edited symbol outside this file.
|
|
687
|
+
const blastRadius = (async () => {
|
|
688
|
+
try {
|
|
689
|
+
const symbolResult = await sendRequest("textDocument/documentSymbol", {
|
|
690
|
+
textDocument: { uri },
|
|
691
|
+
});
|
|
692
|
+
const enclosing = findEnclosingSymbol(flattenSymbols(symbolResult), fromLine - 1);
|
|
693
|
+
if (!enclosing) return undefined;
|
|
694
|
+
|
|
695
|
+
const refsResult = await sendRequest("textDocument/references", {
|
|
696
|
+
textDocument: { uri },
|
|
697
|
+
position: { line: enclosing.selLine, character: enclosing.selChar },
|
|
698
|
+
context: { includeDeclaration: false },
|
|
699
|
+
});
|
|
700
|
+
if (!Array.isArray(refsResult)) return undefined;
|
|
701
|
+
|
|
702
|
+
const external = (refsResult as LspLocation[]).filter((loc) => uriToPath(loc.uri) !== absPath);
|
|
703
|
+
if (external.length === 0) return undefined;
|
|
704
|
+
|
|
705
|
+
const prefix = `${cwd}/`;
|
|
706
|
+
const shown = external.slice(0, 8).map((loc) => {
|
|
707
|
+
const p = uriToPath(loc.uri);
|
|
708
|
+
const rel = p.startsWith(prefix) ? p.slice(prefix.length) : p;
|
|
709
|
+
return `${rel}:${loc.range.start.line + 1}`;
|
|
710
|
+
});
|
|
711
|
+
const more = external.length > shown.length ? ` (+${external.length - shown.length} more)` : "";
|
|
712
|
+
return `${enclosing.name} is referenced in ${external.length} place${external.length === 1 ? "" : "s"} outside this file:\n${shown.map((s) => `- ${s}`).join("\n")}${more}`;
|
|
713
|
+
} catch {
|
|
714
|
+
return undefined;
|
|
715
|
+
}
|
|
716
|
+
})();
|
|
717
|
+
|
|
718
|
+
// 3. Fresh diagnostics for the edited file (skip if the edit tool already reported diagnostics).
|
|
719
|
+
const freshDiagnostics = (async () => {
|
|
720
|
+
if (hasExistingDiagnostics(event.content)) return undefined;
|
|
721
|
+
try {
|
|
722
|
+
await waitForDiagnostics(uri, 1500);
|
|
723
|
+
const errors = (diagnosticsByUri.get(uri) ?? []).filter((d) => (d.severity ?? 1) === 1);
|
|
724
|
+
if (errors.length === 0) return undefined;
|
|
725
|
+
const shown = errors.slice(0, 8).map((d) => {
|
|
726
|
+
const code = d.code ? ` [${d.code}]` : "";
|
|
727
|
+
return `- ${input.path}:${d.range.start.line + 1}:${d.range.start.character + 1}${code}: ${d.message.split("\n")[0]}`;
|
|
728
|
+
});
|
|
729
|
+
const more = errors.length > shown.length ? ` (+${errors.length - shown.length} more)` : "";
|
|
730
|
+
return `${errors.length} error${errors.length === 1 ? "" : "s"} in this file after the edit:\n${shown.join("\n")}${more}`;
|
|
731
|
+
} catch {
|
|
732
|
+
return undefined;
|
|
748
733
|
}
|
|
749
|
-
|
|
734
|
+
})();
|
|
750
735
|
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
736
|
+
const [hoverLines, blast, diag] = await Promise.all([Promise.all(lookups), blastRadius, freshDiagnostics]);
|
|
737
|
+
|
|
738
|
+
const related = hoverLines.filter((l): l is string => !!l);
|
|
739
|
+
if (diag) sections.push(`[Diagnostics \u2014 auto-checked via LSP]\n${diag}`);
|
|
740
|
+
if (blast) sections.push(`[Blast radius \u2014 auto-resolved via LSP]\n${blast}`);
|
|
741
|
+
if (related.length > 0) {
|
|
742
|
+
sections.push(
|
|
743
|
+
`[Related symbols \u2014 auto-resolved via LSP, no extra tool call needed]\n${related.join("\n")}`,
|
|
744
|
+
);
|
|
755
745
|
}
|
|
756
|
-
|
|
746
|
+
if (sections.length === 0) return undefined;
|
|
747
|
+
|
|
748
|
+
const contextBlock = `\n\n${sections.join("\n\n")}`;
|
|
749
|
+
return { content: [...event.content, { type: "text" as const, text: contextBlock }] };
|
|
750
|
+
} catch {
|
|
751
|
+
return undefined;
|
|
752
|
+
}
|
|
757
753
|
});
|
|
754
|
+
});
|
|
758
755
|
|
|
759
|
-
|
|
756
|
+
// ── Shutdown ────────────────────────────────────────────
|
|
760
757
|
|
|
761
|
-
|
|
758
|
+
elyra.on("session_shutdown", async () => {
|
|
762
759
|
if (lspProcess && initialized) {
|
|
763
760
|
try {
|
|
764
761
|
await sendRequest("shutdown", null);
|