refactor(extension): resolve remaining type narrowing diagnostics
Narrow `unknown` types with explicit casts before `in` operator checks
to avoid "Type '{}' may represent a primitive value" errors. Also fix
getActiveTools() which returns string[] (not object[]), removing the
unnecessary .map((t) => t.name). Brings index.ts to zero diagnostics.
This commit is contained in:
31
index.ts
31
index.ts
@@ -26,11 +26,12 @@ function formatHover(result: unknown): string {
|
||||
if (!hover.contents) return "(empty)";
|
||||
|
||||
// MarkupContent
|
||||
const contents = hover.contents as Record<string, unknown>;
|
||||
if (
|
||||
"value" in hover.contents &&
|
||||
typeof (hover.contents as any).value === "string"
|
||||
"value" in contents &&
|
||||
typeof contents.value === "string"
|
||||
) {
|
||||
return (hover.contents as any).value;
|
||||
return contents.value;
|
||||
}
|
||||
// MarkedString | MarkedString[]
|
||||
if (Array.isArray(hover.contents)) {
|
||||
@@ -39,11 +40,10 @@ function formatHover(result: unknown): string {
|
||||
.join("\n");
|
||||
}
|
||||
if (
|
||||
"value" in hover.contents &&
|
||||
typeof (hover.contents as any).language === "string"
|
||||
"value" in contents &&
|
||||
typeof contents.language === "string"
|
||||
) {
|
||||
const ms = hover.contents as any;
|
||||
return `\`\`\`${ms.language}\n${ms.value}\n\`\`\``;
|
||||
return `\`\`\`${contents.language}\n${contents.value}\n\`\`\``;
|
||||
}
|
||||
return JSON.stringify(result, null, 2);
|
||||
}
|
||||
@@ -85,7 +85,12 @@ function formatCompletions(result: unknown): string {
|
||||
let items: any[];
|
||||
if (Array.isArray(result)) {
|
||||
items = result;
|
||||
} else if ("items" in result && Array.isArray((result as any).items)) {
|
||||
} else if (
|
||||
result &&
|
||||
typeof result === "object" &&
|
||||
"items" in result &&
|
||||
Array.isArray((result as any).items)
|
||||
) {
|
||||
items = (result as any).items;
|
||||
} else {
|
||||
return JSON.stringify(result, null, 2);
|
||||
@@ -190,7 +195,13 @@ function formatDocumentSymbols(result: unknown): string {
|
||||
|
||||
// Format Diagnostics - Turn diagnostic messages into readable text.
|
||||
function formatDiagnostics(result: unknown): string {
|
||||
if (!result || !("diagnostics" in result)) return "(no diagnostics)";
|
||||
if (
|
||||
!result ||
|
||||
typeof result !== "object" ||
|
||||
!("diagnostics" in result)
|
||||
) {
|
||||
return "(no diagnostics)";
|
||||
}
|
||||
const diags = (result as any).diagnostics;
|
||||
if (!Array.isArray(diags) || diags.length === 0) return "(no diagnostics)";
|
||||
|
||||
@@ -585,7 +596,7 @@ export default function (pi: ExtensionAPI) {
|
||||
// from the active set so the LLM won't attempt them. When any is enabled,
|
||||
// restore them. Captures current active tools at toggle time.
|
||||
function updateToolVisibility(): void {
|
||||
const current = pi.getActiveTools().map((t) => t.name);
|
||||
const current = pi.getActiveTools();
|
||||
if (servers.every((s) => disabledServers.has(s.id))) {
|
||||
// All disabled — strip LSP tools
|
||||
pi.setActiveTools(current.filter((name) => !lspToolNames.includes(name)));
|
||||
|
||||
Reference in New Issue
Block a user