Skip to content

Commit 69ad512

Browse files
authored
Merge pull request #3 from source-academy/hz/next
Hz/next
2 parents f60821b + 316062b commit 69ad512

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

server/src/rules/ifStatement.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const ifStatementRule = new class extends Rule<IfStatement> {
1111
ast.addDiagnostic(`Missing "else" in "if-else" statement`, DiagnosticSeverity.Error, { start: child.loc!.start, end: child.consequent.loc!.start });
1212
if (child.consequent.type !== STATEMENTS.BLOCK)
1313
ast.addDiagnostic("Missing curly braces around if", DiagnosticSeverity.Error, child.consequent.loc!);
14-
if (child.alternate && child.alternate.type !== STATEMENTS.BLOCK)
14+
if (child.alternate && child.alternate.type !== STATEMENTS.BLOCK && child.alternate.type !== STATEMENTS.IF)
1515
ast.addDiagnostic("Missing curly braces around else", DiagnosticSeverity.Error, child.alternate.loc!);
1616
}
17-
}();
17+
}();

server/src/server.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,15 @@ function getAST(uri: string): AST {
4848
let context = contextCache.get(uri);
4949
if (!context) {
5050
context = DEFAULT_CONTEXT;
51-
contextCache.set(uri, DEFAULT_CONTEXT);
5251
console.log(`No context found for ${uri}, using default context ${JSON.stringify(DEFAULT_CONTEXT)}`);
5352
}
54-
// console.log(`Creating AST for ${uri} with context ${JSON.stringify(context)}`);
5553

56-
// const ast = new AST(documents.get(uri)!.getText(), context, uri, 4);
5754
const ast = new AST(documents.get(uri)!.getText(), context, uri);
5855
astCache.set(uri, ast);
5956
return ast;
6057
}
6158

6259
connection.onInitialize((params: InitializeParams) => {
63-
connection.console.log('LSP INIT');
6460
let capabilities = params.capabilities;
6561

6662
// Does the client support the `workspace/configuration` request?
@@ -213,25 +209,16 @@ connection.onHover((params: HoverParams): Hover | null => {
213209
})
214210

215211
connection.onRequest("source/publishInfo", (info: { [uri: string]: Context }) => {
216-
connection.console.log("Info");
217-
connection.console.log(JSON.stringify(info));
218-
219212
for (const [uri, context] of Object.entries(info)) {
220-
const document = documents.get(uri);
221-
if (document) {
222-
let oldContext = contextCache.get(uri);
223-
if (!oldContext) {
224-
oldContext = context;
225-
contextCache.set(uri, context);
226-
astCache.delete(uri);
213+
const oldContext = contextCache.get(uri);
214+
if (!oldContext || context.chapter !== oldContext.chapter || context.prepend !== oldContext.prepend) {
215+
// Context has been added or changed for this URI
216+
contextCache.set(uri, context);
217+
astCache.delete(uri);
218+
const document = documents.get(uri);
219+
if (document) {
227220
validateTextDocument(document)
228221
}
229-
// Check if context changed
230-
else if (context.chapter !== oldContext.chapter || context.prepend !== oldContext.prepend) {
231-
contextCache.set(uri, context);
232-
astCache.delete(uri);
233-
validateTextDocument(document);
234-
}
235222
}
236223
}
237224

@@ -242,4 +229,4 @@ connection.onRequest("source/publishInfo", (info: { [uri: string]: Context }) =>
242229
documents.listen(connection);
243230

244231
// Listen on the connection
245-
connection.listen();
232+
connection.listen();

0 commit comments

Comments
 (0)