refactor(lsp): remove duplicate LSP tools already provided by OpenCode
Remove lsp_goto_definition, lsp_find_references, lsp_symbols as they duplicate OpenCode's built-in LspGotoDefinition, LspFindReferences, LspDocumentSymbols, and LspWorkspaceSymbols. Keep oh-my-opencode-specific tools: - lsp_diagnostics (OpenCode lacks pull diagnostics) - lsp_servers (server management) - lsp_prepare_rename / lsp_rename (OpenCode lacks rename) Clean up associated dead code: - Client methods: hover, definition, references, symbols, codeAction - Utils: formatLocation, formatSymbolKind, formatDocumentSymbol, etc. - Types: Location, LocationLink, SymbolInfo, DocumentSymbol, etc. - Constants: SYMBOL_KIND_MAP, DEFAULT_MAX_REFERENCES/SYMBOLS -418 lines removed.
This commit is contained in:
+1
-102
@@ -3,21 +3,14 @@ import { fileURLToPath } from "node:url"
|
||||
import { existsSync, readFileSync, writeFileSync } from "fs"
|
||||
import { LSPClient, lspManager } from "./client"
|
||||
import { findServerForExtension } from "./config"
|
||||
import { SYMBOL_KIND_MAP, SEVERITY_MAP } from "./constants"
|
||||
import { SEVERITY_MAP } from "./constants"
|
||||
import type {
|
||||
HoverResult,
|
||||
DocumentSymbol,
|
||||
SymbolInfo,
|
||||
Location,
|
||||
LocationLink,
|
||||
Diagnostic,
|
||||
PrepareRenameResult,
|
||||
PrepareRenameDefaultBehavior,
|
||||
Range,
|
||||
WorkspaceEdit,
|
||||
TextEdit,
|
||||
CodeAction,
|
||||
Command,
|
||||
ServerLookupResult,
|
||||
} from "./types"
|
||||
|
||||
@@ -113,73 +106,11 @@ export async function withLspClient<T>(filePath: string, fn: (client: LSPClient)
|
||||
}
|
||||
}
|
||||
|
||||
export function formatHoverResult(result: HoverResult | null): string {
|
||||
if (!result) return "No hover information available"
|
||||
|
||||
const contents = result.contents
|
||||
if (typeof contents === "string") {
|
||||
return contents
|
||||
}
|
||||
|
||||
if (Array.isArray(contents)) {
|
||||
return contents
|
||||
.map((c) => (typeof c === "string" ? c : c.value))
|
||||
.filter(Boolean)
|
||||
.join("\n\n")
|
||||
}
|
||||
|
||||
if (typeof contents === "object" && "value" in contents) {
|
||||
return contents.value
|
||||
}
|
||||
|
||||
return "No hover information available"
|
||||
}
|
||||
|
||||
export function formatLocation(loc: Location | LocationLink): string {
|
||||
if ("targetUri" in loc) {
|
||||
const uri = uriToPath(loc.targetUri)
|
||||
const line = loc.targetRange.start.line + 1
|
||||
const char = loc.targetRange.start.character
|
||||
return `${uri}:${line}:${char}`
|
||||
}
|
||||
|
||||
const uri = uriToPath(loc.uri)
|
||||
const line = loc.range.start.line + 1
|
||||
const char = loc.range.start.character
|
||||
return `${uri}:${line}:${char}`
|
||||
}
|
||||
|
||||
export function formatSymbolKind(kind: number): string {
|
||||
return SYMBOL_KIND_MAP[kind] || `Unknown(${kind})`
|
||||
}
|
||||
|
||||
export function formatSeverity(severity: number | undefined): string {
|
||||
if (!severity) return "unknown"
|
||||
return SEVERITY_MAP[severity] || `unknown(${severity})`
|
||||
}
|
||||
|
||||
export function formatDocumentSymbol(symbol: DocumentSymbol, indent = 0): string {
|
||||
const prefix = " ".repeat(indent)
|
||||
const kind = formatSymbolKind(symbol.kind)
|
||||
const line = symbol.range.start.line + 1
|
||||
let result = `${prefix}${symbol.name} (${kind}) - line ${line}`
|
||||
|
||||
if (symbol.children && symbol.children.length > 0) {
|
||||
for (const child of symbol.children) {
|
||||
result += "\n" + formatDocumentSymbol(child, indent + 1)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
export function formatSymbolInfo(symbol: SymbolInfo): string {
|
||||
const kind = formatSymbolKind(symbol.kind)
|
||||
const loc = formatLocation(symbol.location)
|
||||
const container = symbol.containerName ? ` (in ${symbol.containerName})` : ""
|
||||
return `${symbol.name} (${kind})${container} - ${loc}`
|
||||
}
|
||||
|
||||
export function formatDiagnostic(diag: Diagnostic): string {
|
||||
const severity = formatSeverity(diag.severity)
|
||||
const line = diag.range.start.line + 1
|
||||
@@ -292,38 +223,6 @@ export function formatWorkspaceEdit(edit: WorkspaceEdit | null): string {
|
||||
return lines.join("\n")
|
||||
}
|
||||
|
||||
export function formatCodeAction(action: CodeAction): string {
|
||||
let result = `[${action.kind || "action"}] ${action.title}`
|
||||
|
||||
if (action.isPreferred) {
|
||||
result += " ⭐"
|
||||
}
|
||||
|
||||
if (action.disabled) {
|
||||
result += ` (disabled: ${action.disabled.reason})`
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
export function formatCodeActions(actions: (CodeAction | Command)[] | null): string {
|
||||
if (!actions || actions.length === 0) return "No code actions available"
|
||||
|
||||
const lines: string[] = []
|
||||
|
||||
for (let i = 0; i < actions.length; i++) {
|
||||
const action = actions[i]
|
||||
|
||||
if ("command" in action && typeof action.command === "string" && !("kind" in action)) {
|
||||
lines.push(`${i + 1}. [command] ${(action as Command).title}`)
|
||||
} else {
|
||||
lines.push(`${i + 1}. ${formatCodeAction(action as CodeAction)}`)
|
||||
}
|
||||
}
|
||||
|
||||
return lines.join("\n")
|
||||
}
|
||||
|
||||
export interface ApplyResult {
|
||||
success: boolean
|
||||
filesModified: string[]
|
||||
|
||||
Reference in New Issue
Block a user