Skip to content

Commit

Permalink
feat: better unknown bracketHandler strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
Yesterday17 committed Jun 24, 2020
1 parent 1ad1c15 commit 5651828
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
2 changes: 2 additions & 0 deletions server/api/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export interface ZenScriptSettings {

showIsProjectWarn: boolean;
autoshowLTCompletion: boolean;

// Whether to show modid autocompletion with bracketHandlers.
modIdItemCompletion: boolean;
}

Expand Down
5 changes: 5 additions & 0 deletions server/parser/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export interface ASTError {
detail: string;
}

export interface ASTBracketHandlerError extends ASTError {
reason: 'BracketHandler error';
isItem: boolean;
}

export interface ASTBody extends ASTNode {
body: ASTNode[];
}
Expand Down
17 changes: 9 additions & 8 deletions server/parser/zsInterpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
ASTNodeUnaryExpression,
ASTNodeXorExpression,
NodeContext,
ASTBracketHandlerError,
} from '.';
import { ERROR_BRACKET_HANDLER } from '../api/constants';
import { zGlobal } from '../api/global';
Expand Down Expand Up @@ -931,14 +932,14 @@ class ZenScriptInterpreter extends ZSParser.getBaseCstVisitorConstructor() {
exist = BracketHandlerMap.get('item').check(['item', ...items]);
}
if (!exist) {
node.errors = [
{
start: node.start,
end: node.end,
reason: ERROR_BRACKET_HANDLER,
detail: `BracketHandler <${node.items.join(':')}> does not exist.`,
},
];
const error: ASTBracketHandlerError = {
start: node.start,
end: node.end,
reason: ERROR_BRACKET_HANDLER,
detail: `BracketHandler <${node.items.join(':')}> does not exist.`,
isItem: items[0] === 'item',
};
node.errors.push(error);
}
return node;
}
Expand Down
35 changes: 22 additions & 13 deletions server/services/zsDocumentContentChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { URI } from 'vscode-uri';
import { ERROR_BRACKET_HANDLER } from '../api/constants';
import { zGlobal } from '../api/global';
import { ZenParsedFile } from '../api/zenParsedFile';
import { ASTBracketHandlerError } from '../parser';
import { getdocumentSettings } from '../utils/setting';
import { ZenScriptActiveService } from './zsService';

export class ZenScriptDocumentContentChange extends ZenScriptActiveService {
Expand Down Expand Up @@ -69,21 +71,28 @@ export class ZenScriptDocumentContentChange extends ZenScriptActiveService {
});

if (file.ast) {
const setting = await getdocumentSettings(textDocument.uri);
file.ast.errors.forEach((error) => {
if (
!file.ignoreBracketErrors ||
error.reason !== ERROR_BRACKET_HANDLER
) {
const diagnotic: Diagnostic = {
severity: DiagnosticSeverity.Error,
range: {
start: textDocument.positionAt(error.start),
end: textDocument.positionAt(error.end),
},
message: error.detail,
};
diagnostics.push(diagnotic);
if (error.reason === ERROR_BRACKET_HANDLER) {
if (file.ignoreBracketErrors) {
return;
}
const e = error as ASTBracketHandlerError;
if (!e.isItem && !setting.modIdItemCompletion) {
return;
}
}

// not ignored
const diagnotic: Diagnostic = {
severity: DiagnosticSeverity.Error,
range: {
start: textDocument.positionAt(error.start),
end: textDocument.positionAt(error.end),
},
message: error.detail,
};
diagnostics.push(diagnotic);
});
}

Expand Down

0 comments on commit 5651828

Please sign in to comment.