"use client"; import { useCallback, useEffect, useMemo } from "react"; import { IconEdit, IconTrash, IconChevronDown, IconExternalLink, IconInfoCircle, } from "@tabler/icons-react"; import { Badge } from "@kandev/ui/badge"; import { Button } from "@kandev/ui/button"; import { Checkbox } from "@kandev/ui/checkbox"; import { Separator } from "@kandev/ui/separator"; import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip"; import { Switch } from "@kandev/ui/switch"; import { Textarea } from "@kandev/ui/textarea"; import { SettingsPageTemplate } from "@/components/settings/settings-page-template"; import { Combobox, type ComboboxOption } from "@/components/combobox"; import { EditableCard } from "@/components/settings/editable-card"; import { EditorForm, type EditorFormState, defaultFormState, formStateFromEditor, getCustomEditorSummary, } from "@/components/settings/editor-form"; import { LSP_DEFAULT_CONFIGS } from "@/lib/lsp/lsp-client-manager"; import type { EditorOption } from "@/lib/types/http"; import type { RequestStatus } from "@/lib/http/use-request"; import { useEditorsSettingsState, useLspConfigActions, useApplyEditors, useEditorRequests, useSaveRequest, buildDefaultEditorOptions, sortCustomEditors, resolveAvailableEditors, isCustomEditor, type EditorsSettingsState, } from "@/components/settings/editors-settings-state"; const LSP_LANGUAGE_OPTIONS = [ { id: "typescript", label: "TypeScript / JavaScript", binary: "typescript-language-server", docsUrl: "https://github.com/typescript-language-server/typescript-language-server#workspace-configuration", installHint: "Installs typescript-language-server and typescript via npm into ~/.kandev/lsp-servers/", }, { id: "go", label: "Go", binary: "gopls", docsUrl: "https://github.com/golang/tools/blob/master/gopls/doc/settings.md", installHint: 'Runs "go install golang.org/x/tools/gopls@latest". Requires Go to be installed.', }, { id: "rust", label: "Rust", binary: "rust-analyzer", docsUrl: "https://rust-analyzer.github.io/book/configuration.html", installHint: "Downloads the rust-analyzer binary from GitHub releases into ~/.kandev/lsp-servers/", }, { id: "python", label: "Python", binary: "pyright-langserver", docsUrl: "https://microsoft.github.io/pyright/#/settings", installHint: "Installs pyright via npm into ~/.kandev/lsp-servers/", }, ]; type LspLanguageCardsProps = { lspAutoStartLanguages: string[]; lspAutoInstallLanguages: string[]; toggleAutoStart: (langId: string, checked: boolean) => void; toggleAutoInstall: (langId: string, checked: boolean) => void; }; function LspLanguageCards({ lspAutoStartLanguages, lspAutoInstallLanguages, toggleAutoStart, toggleAutoInstall, }: LspLanguageCardsProps) { return (
Language Servers
Auto-start language servers when opening files to get diagnostics, hover info, and go-to-definition. You can also toggle each server on/off per file.
When enabled, install your project's dependencies (e.g.{" "} npm install via repository setup scripts) to avoid missing type errors.
{LSP_LANGUAGE_OPTIONS.map((lang) => (
{lang.label}
{lang.binary}
Auto-start toggleAutoStart(lang.id, checked === true)} />
toggleAutoInstall(lang.id, checked === true)} className="h-3.5 w-3.5" /> {lang.installHint}
))}
); } type LspServerConfigSectionProps = { lspConfigStrings: Record; lspConfigErrors: Record; expandedConfigLang: string | null; setExpandedConfigLang: (lang: string | null) => void; updateLspConfigString: (langId: string, value: string) => void; }; function LspServerConfigSection({ lspConfigStrings, lspConfigErrors, expandedConfigLang, setExpandedConfigLang, updateLspConfigString, }: LspServerConfigSectionProps) { return (
Server Configuration
Override settings sent to each language server via{" "} workspace/configuration. JSON format.
{LSP_LANGUAGE_OPTIONS.map((lang) => { const isExpanded = expandedConfigLang === lang.id; const configStr = lspConfigStrings[lang.id] ?? ""; const defaultConfig = LSP_DEFAULT_CONFIGS[lang.id]; const hasDefaults = defaultConfig && Object.keys(defaultConfig).length > 0; const error = lspConfigErrors[lang.id]; return (
{isExpanded && (
{hasDefaults && (
Defaults:{" "} {JSON.stringify(defaultConfig)}
)} View available settings