Skip to content

Commit 8259aee

Browse files
committed
temp
1 parent 8d4f749 commit 8259aee

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

client/src/extension.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ export function activate(context: ExtensionContext) {
5454
clientOptions
5555
);
5656

57-
// Start the client. This will also launch the server
58-
client.start();
57+
// Start the client. This will also launch the server
58+
(async function () {
59+
console.log("Going to call client.start()");
60+
await client.start();
61+
console.log("client.start() called");
62+
})();
5963

6064
context.subscriptions.push(
6165
commands.registerCommand("sourcejs.setLanguageVersion", async () => {

server/src/server.ts

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,28 @@ let documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);
4343

4444
let hasConfigurationCapability: boolean = false;
4545
let hasWorkspaceFolderCapability: boolean = false;
46-
let context: Context = { chapter: Chapter.SOURCE_1 };
4746

47+
// let context: Context = { chapter: Chapter.SOURCE_1 };
48+
let contextCache: Map<string, Context> = new Map();
4849
let astCache: Map<string, AST> = new Map();
4950

5051
function getAST(uri: string): AST {
5152
if (astCache.has(uri)) return astCache.get(uri)!;
5253

54+
let context = contextCache.get(uri)
55+
if (!context) {
56+
context = { chapter: Chapter.SOURCE_1 };
57+
console.log(`No context found for ${uri}, using default context ${JSON.stringify(context)}`);
58+
}
59+
console.log(`Creating AST for ${uri} with context ${JSON.stringify(context)}`);
60+
5361
const ast = new AST(documents.get(uri)!.getText(), context, uri);
5462
astCache.set(uri, ast);
5563
return ast;
5664
}
5765

5866
connection.onInitialize((params: InitializeParams) => {
67+
connection.console.log('LSP INIT');
5968
let capabilities = params.capabilities;
6069

6170
// Does the client support the `workspace/configuration` request?
@@ -103,16 +112,16 @@ connection.onInitialized(() => {
103112
}
104113
});
105114

106-
// Custom request to set the language version
107-
connection.onRequest("setLanguageVersion", (params: { version: string }) => {
108-
if (Object.keys(chapter_names).includes(params.version)) {
109-
context = { chapter: chapter_names[params.version as keyof typeof chapter_names] }
110-
astCache.clear();
111-
documents.all().forEach(validateTextDocument);
112-
return { success: true };
113-
}
114-
else return { success: false };
115-
});
115+
// // Custom request to set the language version
116+
// connection.onRequest("setLanguageVersion", (params: { version: string }) => {
117+
// if (Object.keys(chapter_names).includes(params.version)) {
118+
// context = { chapter: chapter_names[params.version as keyof typeof chapter_names] }
119+
// astCache.clear();
120+
// documents.all().forEach(validateTextDocument);
121+
// return { success: true };
122+
// }
123+
// else return { success: false };
124+
// });
116125

117126
// The content of a text document has changed. This event is emitted
118127
// when the text document first opened or when its content has changed.
@@ -129,7 +138,7 @@ async function validateTextDocument(document: TextDocument): Promise<void> {
129138
connection.sendDiagnostics({ uri: document.uri, diagnostics: getAST(document.uri).getDiagnostics() });
130139
}
131140

132-
// TODO: handle file deletion and creation
141+
// TODO: handle file deletion and creation
133142
connection.onDidChangeWatchedFiles(_change => {
134143
// Monitored files have change in VS Code
135144
connection.console.log('We received a file change event');
@@ -207,6 +216,16 @@ connection.onHover((params: HoverParams): Hover | null => {
207216
return getAST(params.textDocument.uri).onHover(position);
208217
})
209218

219+
connection.onNotification("source/publishInfo", (info) => {
220+
connection.console.log("Info");
221+
connection.console.log(info);
222+
223+
contextCache = new Map(Object.entries(info));
224+
// TODO: We only need to revalidate the documents that have changed
225+
astCache.clear();
226+
documents.all().forEach(validateTextDocument);
227+
return { success: true };
228+
})
210229

211230
// Make the text document manager listen on the connection
212231
documents.listen(connection);

0 commit comments

Comments
 (0)