11import { 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' ;
33import { existsSync , readFileSync , statSync } from 'fs' ;
44import { sysparser , syxparser } from './ast.js' ;
55import { 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 */
2023export 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 ;
0 commit comments