@akiojin/unity-mcp-server 2.41.5 → 2.41.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/lsp/CSharpLspUtils.js +27 -6
- package/src/lsp/LspProcessManager.js +22 -17
- package/src/lsp/LspRpcClient.js +9 -1
package/package.json
CHANGED
|
@@ -131,13 +131,32 @@ export class CSharpLspUtils {
|
|
|
131
131
|
async ensureLocal(rid) {
|
|
132
132
|
const p = this.getLocalPath(rid);
|
|
133
133
|
const desired = this.getDesiredVersion();
|
|
134
|
-
|
|
134
|
+
|
|
135
|
+
// バージョン取得失敗時もバイナリが存在すれば使用
|
|
136
|
+
if (!desired) {
|
|
137
|
+
if (fs.existsSync(p)) {
|
|
138
|
+
logger.warn('[csharp-lsp] version not found, using existing binary');
|
|
139
|
+
return p;
|
|
140
|
+
}
|
|
141
|
+
throw new Error('mcp-server version not found; cannot resolve LSP tag');
|
|
142
|
+
}
|
|
143
|
+
|
|
135
144
|
const current = this.readLocalVersion(rid);
|
|
136
145
|
if (fs.existsSync(p) && current === desired) return p;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
146
|
+
|
|
147
|
+
// ダウンロード失敗時のフォールバック
|
|
148
|
+
try {
|
|
149
|
+
const resolved = await this.autoDownload(rid, desired);
|
|
150
|
+
if (!fs.existsSync(p)) throw new Error('csharp-lsp binary not found after download');
|
|
151
|
+
this.writeLocalVersion(rid, resolved || desired);
|
|
152
|
+
return p;
|
|
153
|
+
} catch (e) {
|
|
154
|
+
if (fs.existsSync(p)) {
|
|
155
|
+
logger.warn(`[csharp-lsp] download failed, using existing binary: ${e.message}`);
|
|
156
|
+
return p;
|
|
157
|
+
}
|
|
158
|
+
throw e;
|
|
159
|
+
}
|
|
141
160
|
}
|
|
142
161
|
|
|
143
162
|
async autoDownload(rid, version) {
|
|
@@ -194,7 +213,9 @@ export class CSharpLspUtils {
|
|
|
194
213
|
if (process.platform !== 'win32') fs.chmodSync(dest, 0o755);
|
|
195
214
|
} catch {}
|
|
196
215
|
logger.info(`[csharp-lsp] downloaded: ${path.basename(dest)} @ ${path.dirname(dest)}`);
|
|
197
|
-
|
|
216
|
+
// manifestから実際のバージョンを取得(信頼性の高いソースとして使用)
|
|
217
|
+
const actualVersion = manifest.version || targetVersion;
|
|
218
|
+
return actualVersion;
|
|
198
219
|
}
|
|
199
220
|
|
|
200
221
|
async fetchLatestReleaseVersion(repo) {
|
|
@@ -17,23 +17,28 @@ export class LspProcessManager {
|
|
|
17
17
|
if (this.state.proc && !this.state.proc.killed) return this.state.proc;
|
|
18
18
|
if (this.state.starting) return this.state.starting;
|
|
19
19
|
this.state.starting = (async () => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this.state.proc
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
20
|
+
try {
|
|
21
|
+
const rid = this.utils.detectRid();
|
|
22
|
+
const bin = await this.utils.ensureLocal(rid);
|
|
23
|
+
const proc = spawn(bin, { stdio: ['pipe', 'pipe', 'pipe'] });
|
|
24
|
+
proc.on('error', e => logger.error(`[csharp-lsp] process error: ${e.message}`));
|
|
25
|
+
proc.on('close', (code, sig) => {
|
|
26
|
+
logger.warn(`[csharp-lsp] exited code=${code} signal=${sig || ''}`);
|
|
27
|
+
if (this.state.proc === proc) {
|
|
28
|
+
this.state.proc = null;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
proc.stderr.on('data', d => {
|
|
32
|
+
const s = String(d || '').trim();
|
|
33
|
+
if (s) logger.debug(`[csharp-lsp] ${s}`);
|
|
34
|
+
});
|
|
35
|
+
this.state.proc = proc;
|
|
36
|
+
logger.info(`[csharp-lsp] started (pid=${proc.pid})`);
|
|
37
|
+
return proc;
|
|
38
|
+
} catch (e) {
|
|
39
|
+
logger.error(`[csharp-lsp] failed to start: ${e.message}`);
|
|
40
|
+
throw e;
|
|
41
|
+
}
|
|
37
42
|
})();
|
|
38
43
|
try {
|
|
39
44
|
return await this.state.starting;
|
package/src/lsp/LspRpcClient.js
CHANGED
|
@@ -64,9 +64,17 @@ export class LspRpcClient {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
writeMessage(obj) {
|
|
67
|
+
if (!this.proc || this.proc.killed) {
|
|
68
|
+
throw new Error('LSP process not available');
|
|
69
|
+
}
|
|
67
70
|
const json = JSON.stringify(obj);
|
|
68
71
|
const payload = `Content-Length: ${Buffer.byteLength(json, 'utf8')}\r\n\r\n${json}`;
|
|
69
|
-
|
|
72
|
+
try {
|
|
73
|
+
this.proc.stdin.write(payload, 'utf8');
|
|
74
|
+
} catch (e) {
|
|
75
|
+
logger.error(`[csharp-lsp] writeMessage failed: ${e.message}`);
|
|
76
|
+
throw e;
|
|
77
|
+
}
|
|
70
78
|
}
|
|
71
79
|
|
|
72
80
|
async initialize() {
|