-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain-vs.ts
107 lines (87 loc) · 2.51 KB
/
main-vs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"use strict";
import {
createConnection,
InitializedParams,
InitializeParams,
InitializeResult,
ProposedFeatures,
TextDocuments,
TextDocumentSyncKind
} from "vscode-languageserver";
import { CodeStreamAgent, FileLspLogger, NullLspLogger } from "./agent";
import { Logger } from "./logger";
import { AgentOptions, LogoutReason } from "./protocol/agent.protocol";
let logPath;
process.argv.forEach(function(val, index, array) {
if (val && val.indexOf("--log=") === 0) {
logPath = val.substring(6);
}
});
const logger = logPath != null ? new FileLspLogger(logPath) : undefined;
// Staged change
// Create a connection for the server. The connection uses Node's IPC as a transport.
// Also include all preview / proposed LSP features.
const connection = createConnection(ProposedFeatures.all);
let initializeParams: InitializeParams | undefined;
const documents = new TextDocuments();
const agentConfig = {
documents: documents,
logger: logger,
onInitialize: async (e: InitializeParams) => {
initializeParams = e;
const agentOptions = e.initializationOptions! as AgentOptions;
Logger.log(
`Agent for CodeStream v${agentOptions.extension.versionFormatted} in ${agentOptions.ide.name} (v${agentOptions.ide.version}) initializing...`
);
return {
capabilities: {
textDocumentSync: TextDocumentSyncKind.Full
},
result: null
} as InitializeResult;
},
// This doesn't get called by Visual Studio, so just ignore it
onInitialized: (e: InitializedParams) => {
Logger.log("onInitialized");
}
};
let agent = new CodeStreamAgent(connection, agentConfig);
connection.onRequest("codestream/onInitialized", async (agentOptions: AgentOptions) => {
if (agent.signedIn) {
restartAgent();
}
Logger.log(`Agent(${agentOptions.ide.name}) initializing...`);
const params = {
...initializeParams,
initializationOptions: agentOptions
} as InitializeParams;
let response;
try {
response = await agent.onInitialize(params);
if (response.result!.error == null) {
Logger.log("onInitialized...");
await agent.onInitialized({});
Logger.log(`Agent(${agentOptions.ide.name}) initialize`);
}
} catch (ex) {
Logger.error(ex);
response = {
result: {
error: ex.message
}
};
}
return response;
});
connection.onRequest("codestream/logout", async _ => {
await agent.logout(LogoutReason.Unknown);
restartAgent();
});
function restartAgent() {
Logger.log("Restarting agent...");
if (agent != null) {
agent.dispose();
}
agent = new CodeStreamAgent(connection, agentConfig);
}
connection.listen();