fixing imports

This commit is contained in:
2026-02-04 21:32:30 -05:00
parent 74b0a0dbab
commit db79856b08
166 changed files with 1986 additions and 982 deletions

View File

@@ -49,7 +49,10 @@ export interface DocumentSymbol {
}
export interface Hover {
contents: string | { kind: string; value: string } | Array<string | { kind: string; value: string }>;
contents:
| string
| { kind: string; value: string }
| Array<string | { kind: string; value: string }>;
range?: Range;
}
@@ -163,7 +166,10 @@ export class LSPClient extends EventEmitter {
private handleNotification(method: string, params: unknown): void {
if (method === "textDocument/publishDiagnostics") {
const { uri, diagnostics } = params as { uri: string; diagnostics: Diagnostic[] };
const { uri, diagnostics } = params as {
uri: string;
diagnostics: Diagnostic[];
};
this.diagnosticsMap.set(uri, diagnostics);
this.emit("diagnostics", uri, diagnostics);
}
@@ -213,7 +219,9 @@ export class LSPClient extends EventEmitter {
async initialize(): Promise<void> {
if (this.initialized) return;
const result = await this.request<{ capabilities: Record<string, unknown> }>("initialize", {
const result = await this.request<{
capabilities: Record<string, unknown>;
}>("initialize", {
processId: process.pid,
rootUri: `file://${this.root}`,
rootPath: this.root,
@@ -319,45 +327,60 @@ export class LSPClient extends EventEmitter {
}
}
async getDefinition(filePath: string, position: Position): Promise<Location | Location[] | null> {
async getDefinition(
filePath: string,
position: Position,
): Promise<Location | Location[] | null> {
const uri = `file://${filePath}`;
try {
return await this.request<Location | Location[] | null>("textDocument/definition", {
textDocument: { uri },
position,
});
return await this.request<Location | Location[] | null>(
"textDocument/definition",
{
textDocument: { uri },
position,
},
);
} catch {
return null;
}
}
async getReferences(filePath: string, position: Position, includeDeclaration = true): Promise<Location[]> {
async getReferences(
filePath: string,
position: Position,
includeDeclaration = true,
): Promise<Location[]> {
const uri = `file://${filePath}`;
try {
const result = await this.request<Location[] | null>("textDocument/references", {
textDocument: { uri },
position,
context: { includeDeclaration },
});
const result = await this.request<Location[] | null>(
"textDocument/references",
{
textDocument: { uri },
position,
context: { includeDeclaration },
},
);
return result ?? [];
} catch {
return [];
}
}
async getCompletions(filePath: string, position: Position): Promise<CompletionItem[]> {
async getCompletions(
filePath: string,
position: Position,
): Promise<CompletionItem[]> {
const uri = `file://${filePath}`;
try {
const result = await this.request<{ items: CompletionItem[] } | CompletionItem[] | null>(
"textDocument/completion",
{
textDocument: { uri },
position,
},
);
const result = await this.request<
{ items: CompletionItem[] } | CompletionItem[] | null
>("textDocument/completion", {
textDocument: { uri },
position,
});
if (!result) return [];
return Array.isArray(result) ? result : result.items;
@@ -370,9 +393,12 @@ export class LSPClient extends EventEmitter {
const uri = `file://${filePath}`;
try {
const result = await this.request<DocumentSymbol[] | null>("textDocument/documentSymbol", {
textDocument: { uri },
});
const result = await this.request<DocumentSymbol[] | null>(
"textDocument/documentSymbol",
{
textDocument: { uri },
},
);
return result ?? [];
} catch {
return [];

View File

@@ -152,7 +152,10 @@ export const openFile = async (filePath: string): Promise<void> => {
}
};
export const updateFile = async (filePath: string, content: string): Promise<void> => {
export const updateFile = async (
filePath: string,
content: string,
): Promise<void> => {
const absolutePath = path.resolve(filePath);
const clients = await getClientsForFile(absolutePath);
@@ -176,7 +179,10 @@ export const closeFile = async (filePath: string): Promise<void> => {
}
};
export const getHover = async (filePath: string, position: Position): Promise<Hover | null> => {
export const getHover = async (
filePath: string,
position: Position,
): Promise<Hover | null> => {
const absolutePath = path.resolve(filePath);
const clients = await getClientsForFile(absolutePath);
@@ -213,7 +219,11 @@ export const getReferences = async (
const allRefs: Location[] = [];
for (const client of clients) {
const refs = await client.getReferences(absolutePath, position, includeDeclaration);
const refs = await client.getReferences(
absolutePath,
position,
includeDeclaration,
);
allRefs.push(...refs);
}
@@ -243,7 +253,9 @@ export const getCompletions = async (
return allCompletions;
};
export const getDocumentSymbols = async (filePath: string): Promise<DocumentSymbol[]> => {
export const getDocumentSymbols = async (
filePath: string,
): Promise<DocumentSymbol[]> => {
const absolutePath = path.resolve(filePath);
const clients = await getClientsForFile(absolutePath);
@@ -255,7 +267,9 @@ export const getDocumentSymbols = async (filePath: string): Promise<DocumentSymb
return [];
};
export const getDiagnostics = (filePath?: string): Map<string, Diagnostic[]> => {
export const getDiagnostics = (
filePath?: string,
): Map<string, Diagnostic[]> => {
const allDiagnostics = new Map<string, Diagnostic[]>();
for (const client of state.clients.values()) {
@@ -278,7 +292,9 @@ export const getStatus = (): {
connected: Array<{ serverId: string; root: string }>;
broken: string[];
} => {
const connected = Array.from(state.clients.values()).map((client) => client.getInfo());
const connected = Array.from(state.clients.values()).map((client) =>
client.getInfo(),
);
const broken = Array.from(state.broken);
return { connected, broken };
@@ -303,7 +319,11 @@ export const shutdown = (): void => {
};
export const onDiagnostics = (
callback: (data: { uri: string; diagnostics: Diagnostic[]; serverId: string }) => void,
callback: (data: {
uri: string;
diagnostics: Diagnostic[];
serverId: string;
}) => void,
): (() => void) => {
events.on("diagnostics", callback);
return () => events.off("diagnostics", callback);

View File

@@ -166,9 +166,13 @@ export const LANGUAGE_EXTENSIONS: Record<string, string> = {
export const getLanguageId = (filePath: string): string | null => {
const ext = filePath.includes(".")
? "." + filePath.split(".").pop()
: filePath.split("/").pop() ?? "";
: (filePath.split("/").pop() ?? "");
return LANGUAGE_EXTENSIONS[ext] ?? LANGUAGE_EXTENSIONS[filePath.split("/").pop() ?? ""] ?? null;
return (
LANGUAGE_EXTENSIONS[ext] ??
LANGUAGE_EXTENSIONS[filePath.split("/").pop() ?? ""] ??
null
);
};
export const getExtensionsForLanguage = (languageId: string): string[] => {

View File

@@ -54,8 +54,12 @@ const findProjectRoot = async (
const findBinary = async (name: string): Promise<string | null> => {
try {
const command = process.platform === "win32" ? `where ${name}` : `which ${name}`;
const result = execSync(command, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
const command =
process.platform === "win32" ? `where ${name}` : `which ${name}`;
const result = execSync(command, {
encoding: "utf-8",
stdio: ["pipe", "pipe", "pipe"],
});
return result.trim().split("\n")[0] || null;
} catch {
return null;
@@ -83,7 +87,12 @@ export const SERVERS: Record<string, ServerInfo> = {
id: "python",
name: "Pyright",
extensions: [".py", ".pyi"],
rootPatterns: ["pyproject.toml", "setup.py", "requirements.txt", "pyrightconfig.json"],
rootPatterns: [
"pyproject.toml",
"setup.py",
"requirements.txt",
"pyrightconfig.json",
],
command: "pyright-langserver",
args: ["--stdio"],
},
@@ -160,7 +169,12 @@ export const SERVERS: Record<string, ServerInfo> = {
id: "eslint",
name: "ESLint Language Server",
extensions: [".ts", ".tsx", ".js", ".jsx"],
rootPatterns: [".eslintrc", ".eslintrc.js", ".eslintrc.json", "eslint.config.js"],
rootPatterns: [
".eslintrc",
".eslintrc.js",
".eslintrc.json",
"eslint.config.js",
],
command: "vscode-eslint-language-server",
args: ["--stdio"],
},
@@ -212,8 +226,7 @@ export const getServersForFile = (filePath: string): ServerInfo[] => {
return Object.values(SERVERS).filter((server) => {
return (
server.extensions.includes(ext) ||
server.extensions.includes(fileName)
server.extensions.includes(ext) || server.extensions.includes(fileName)
);
});
};
@@ -249,7 +262,9 @@ export const spawnServer = async (
return { process: proc };
};
export const isServerAvailable = async (server: ServerInfo): Promise<boolean> => {
export const isServerAvailable = async (
server: ServerInfo,
): Promise<boolean> => {
const binary = await findBinary(server.command);
return binary !== null;
};