MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / upsertCustomServer

Function upsertCustomServer

src/settings/lspConfigUtils.js:68–136  ·  view source on GitHub ↗
(serverId, config)

Source from the content-addressed store, hash-verified

66}
67
68export async function upsertCustomServer(serverId, config) {
69 const key = normalizeServerId(serverId);
70 if (!key) {
71 throw new Error("Server id is required");
72 }
73
74 const existingServer = lspApi.servers.get(key);
75 if (existingServer && getServerOverride(key).custom !== true) {
76 throw new Error("A built-in server already uses this id");
77 }
78
79 const languages = normalizeLanguages(config.languages);
80 if (!languages.length) {
81 throw new Error("At least one language id is required");
82 }
83
84 const current = cloneLspSettings();
85 current.servers = current.servers || {};
86 const existing = current.servers[key] || {};
87 const hasTransport = Object.prototype.hasOwnProperty.call(
88 config,
89 "transport",
90 );
91 const hasLauncher = Object.prototype.hasOwnProperty.call(config, "launcher");
92 const nextConfig = {
93 ...existing,
94 ...config,
95 custom: true,
96 label: config.label || existing.label || key,
97 languages,
98 transport: hasTransport
99 ? config.transport
100 : existing.transport || { kind: "websocket" },
101 launcher: hasLauncher ? config.launcher : existing.launcher,
102 runtimes: config.runtimes || existing.runtimes,
103 enabled: config.enabled !== false,
104 };
105
106 const installKind = nextConfig.launcher?.install?.kind;
107 if (installKind && installKind !== "shell") {
108 const providedExecutable =
109 nextConfig.launcher.install.binaryPath ||
110 nextConfig.launcher.install.executable;
111 if (!providedExecutable) {
112 throw new Error(
113 "Managed installers must declare the executable path or command they provide",
114 );
115 }
116 }
117
118 current.servers[key] = nextConfig;
119 await appSettings.update({ lsp: current }, false);
120
121 const definition = {
122 id: key,
123 label: nextConfig.label,
124 languages,
125 transport: nextConfig.transport,

Callers 1

callbackFunction · 0.90

Calls 7

normalizeServerIdFunction · 0.85
getServerOverrideFunction · 0.85
normalizeLanguagesFunction · 0.85
cloneLspSettingsFunction · 0.85
callMethod · 0.80
getMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected