Skip to content

Commit 535053e

Browse files
committed
fix exportableCheck diagnostics
1 parent 9beac25 commit 535053e

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

src/diagnostic.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CodeAction, CodeActionKind, Diagnostic, DiagnosticSeverity, DocumentDiagnosticReportKind, FullDocumentDiagnosticReport, Range } from 'lsp-types';
2-
import { ImportStatement, NodeType, ProgramStatement, RuleStatement, Statement, TokenType, isCompilerError, statementIsA } from './types.js';
2+
import { GlobalStatement, ImportStatement, NodeType, ProgramStatement, RuleStatement, Statement, TokenType, isCompilerError, statementIsA } from './types.js';
33
import { existsSync, readFileSync, statSync } from 'fs';
44
import { sysparser, syxparser } from './ast.js';
55
import { tokenizeSys, tokenizeSyx } from './lexer.js';
@@ -15,6 +15,9 @@ const semiRange: Range = { end: { line: 0, character: 1 }, start: { line: 0, cha
1515
* Creates a diagnostic report from the file path given.
1616
* @param {string} filePath Path of the file to create a report.
1717
* @param {string} fileContent Content of the file if it is already fetched.
18+
* @author efekos
19+
* @version 1.0.1
20+
* @since 0.0.2-alpha
1821
* @returns A diagnostic report language servers can use.
1922
*/
2023
export function createSyntaxScriptDiagnosticReport(filePath: string, fileContent?: string): FullDocumentDiagnosticReport {
@@ -28,7 +31,7 @@ export function createSyntaxScriptDiagnosticReport(filePath: string, fileContent
2831
const tokens = (isSyx ? tokenizeSyx : tokenizeSys)(content);
2932
const ast = (isSyx ? syxparser : sysparser).parseTokens(tokens, filePath);
3033

31-
items.push(...exportableCheck(ast, filePath));
34+
items.push(...exportableCheck(ast.body, filePath));
3235
items.push(...ruleConflictCheck(ast, filePath));
3336
items.push(...sameRuleCheck(ast, filePath));
3437
items.push(...importedExistentCheck(ast, filePath));
@@ -41,6 +44,8 @@ export function createSyntaxScriptDiagnosticReport(filePath: string, fileContent
4144
source: 'syntax-script',
4245
data: error.actions
4346
});
47+
} else {
48+
items.push({message:`Parser Error: ${error.message}`,range:{end:{line:0,character:1},start:{line:0,character:0}},severity:DiagnosticSeverity.Warning});
4449
}
4550
} finally {
4651
return { items, kind: DocumentDiagnosticReportKind.Full };
@@ -214,20 +219,11 @@ function importedExistentCheck(ast: ProgramStatement, filePath: string): Diagnos
214219
}
215220

216221
// Checks if every exported statement it actually exportable
217-
// TODO this doesnt work for some reason
218-
function exportableCheck(ast: ProgramStatement, filePath: string): Diagnostic[] {
222+
function exportableCheck(statements: Statement[], filePath: string): Diagnostic[] {
219223

220224
const items: Diagnostic[] = [];
221225

222-
ast.body.forEach(stmt => {
223-
224-
items.push({
225-
message: `${stmt.modifiers.map(r => r.type).join(',')}l`,
226-
range: subRange(stmt.range),
227-
severity: DiagnosticSeverity.Error,
228-
source: 'syntax-script',
229-
data: []
230-
});
226+
statements.forEach(stmt => {
231227

232228
if (stmt.modifiers.some(t => t.type === TokenType.ExportKeyword) && !dictionary.ExportableNodeTypes.includes(stmt.type)) items.push({
233229
message: 'This statement cannot be exported.',
@@ -251,7 +247,7 @@ function exportableCheck(ast: ProgramStatement, filePath: string): Diagnostic[]
251247
] as CodeAction[]
252248
});
253249

254-
// if (dictionary.ExportableNodeTypes.includes(stmt.type)) c((stmt as GlobalStatement).body);
250+
if (dictionary.StatementTypesWithBody.includes(stmt.type)) items.push(...exportableCheck((stmt as GlobalStatement).body,filePath));
255251
});
256252

257253
return items;

src/dictionary/dictionary.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export namespace dictionary {
5454
export const PrimitiveTypes: string[] = ['int', 'decimal', 'boolean', 'string'];
5555
export const Keywords: string[] = ['export', 'rule', 'keyword', 'import', 'operator', 'function', 'global'];
5656
export const Functionaries: Functionary[] = func;
57-
export const ExportableNodeTypes: NodeType[] = [NodeType.Function,NodeType.Operator,NodeType.Keyword,NodeType.Rule];
57+
export const ExportableNodeTypes: NodeType[] = [NodeType.Function,NodeType.Operator,NodeType.Keyword,NodeType.Rule,NodeType.Global];
5858
export const StatementTypesWithBody: NodeType[] = [NodeType.Operator,NodeType.Function,NodeType.Global];
5959

6060
}

0 commit comments

Comments
 (0)