1
1
import { CodeAction , CodeActionKind , Diagnostic , DiagnosticSeverity , DocumentDiagnosticReportKind , FullDocumentDiagnosticReport , Range } from 'lsp-types' ;
2
- import { FunctionStatement , GlobalStatement , ImportStatement , KeywordStatement , NodeType , OperatorStatement , ProgramStatement , RuleStatement , Statement , TokenType , isCompilerError , statementIsA } from './types.js' ;
2
+ import { FunctionStatement , GlobalStatement , IdentifierExpression , ImportStatement , KeywordStatement , NodeType , OperatorStatement , ProgramStatement , RuleStatement , Statement , TokenType , isCompilerError , statementIsA } from './types.js' ;
3
3
import { existsSync , readFileSync , statSync } from 'fs' ;
4
4
import { sysparser , syxparser } from './ast.js' ;
5
5
import { tokenizeSys , tokenizeSyx } from './lexer.js' ;
@@ -65,12 +65,12 @@ function ruleConflictCheck(ast: ProgramStatement, filePath: string): Diagnostic[
65
65
66
66
ast . body . filter ( r => statementIsA ( r , NodeType . Rule ) ) . filter ( r => r . range !== stmt . range ) . map ( r => r as RuleStatement ) . forEach ( otherRules => {
67
67
if ( dictRule . conflicts . includes ( otherRules . rule . value ) ) items . push ( {
68
- message : `Rule '${ otherRules . rule } ' conflicts with '${ stmt . rule } ', Both of them should not be defined.` ,
69
- range : subRange ( otherRules . range ) ,
68
+ message : `Rule '${ otherRules . rule . value } ' conflicts with '${ stmt . rule . value } ', Both of them should not be defined.` ,
69
+ range : subRange ( otherRules . rule . range ) ,
70
70
severity : DiagnosticSeverity . Warning ,
71
71
data : [
72
72
{
73
- title : `Remove ${ stmt . rule } definition` ,
73
+ title : `Remove ${ stmt . rule . value } definition` ,
74
74
kind : CodeActionKind . QuickFix ,
75
75
edit : {
76
76
changes : {
@@ -84,7 +84,7 @@ function ruleConflictCheck(ast: ProgramStatement, filePath: string): Diagnostic[
84
84
}
85
85
} ,
86
86
{
87
- title : `Remove ${ otherRules . rule } definition` ,
87
+ title : `Remove ${ otherRules . rule . value } definition` ,
88
88
kind : CodeActionKind . QuickFix ,
89
89
edit : {
90
90
changes : {
@@ -114,8 +114,8 @@ function sameRuleCheck(ast: ProgramStatement, filePath: string): Diagnostic[] {
114
114
if ( statementIsA ( stmt , NodeType . Rule ) ) {
115
115
ast . body . filter ( r => statementIsA ( r , NodeType . Rule ) ) . filter ( r => r . range !== stmt . range ) . map ( r => r as RuleStatement ) . forEach ( otherRules => {
116
116
if ( otherRules . rule === stmt . rule ) items . push ( {
117
- message : `Rule '${ stmt . rule } ' is already defined.` ,
118
- range : subRange ( stmt . range ) ,
117
+ message : `Rule '${ stmt . rule . value } ' is already defined.` ,
118
+ range : subRange ( stmt . rule . range ) ,
119
119
severity : DiagnosticSeverity . Error ,
120
120
data : [
121
121
{
@@ -152,7 +152,7 @@ function importedExistentCheck(ast: ProgramStatement, filePath: string): Diagnos
152
152
if ( ! existsSync ( fullPath ) ) items . push ( {
153
153
message : `Can't find file '${ fullPath } ' imported from '${ filePathButPath } '` ,
154
154
severity : DiagnosticSeverity . Error ,
155
- range : subRange ( stmt . range ) ,
155
+ range : subRange ( stmt . path . range ) ,
156
156
data : [
157
157
{
158
158
title : 'Remove this import statement' ,
@@ -174,7 +174,7 @@ function importedExistentCheck(ast: ProgramStatement, filePath: string): Diagnos
174
174
if ( ! status . isFile ( ) ) items . push ( {
175
175
message : `'${ fullPath } ' imported from '${ filePathButPath } ' doesn't seem to be a file.` ,
176
176
severity : DiagnosticSeverity . Error ,
177
- range : subRange ( stmt . range ) ,
177
+ range : subRange ( stmt . path . range ) ,
178
178
data : [
179
179
{
180
180
title : 'Remove this import statement' ,
@@ -193,7 +193,7 @@ function importedExistentCheck(ast: ProgramStatement, filePath: string): Diagnos
193
193
if ( ! fullPath . endsWith ( '.syx' ) ) items . push ( {
194
194
message : `'${ fullPath } ' imported from '${ filePathButPath } ' cannot be imported.` ,
195
195
severity : DiagnosticSeverity . Error ,
196
- range : subRange ( stmt . range ) ,
196
+ range : subRange ( stmt . path . range ) ,
197
197
data : [
198
198
{
199
199
title : 'Remove this import statement' ,
@@ -262,7 +262,7 @@ function exportableCheck(statements: Statement[], filePath: string): Diagnostic[
262
262
263
263
if ( stmt . modifiers . some ( t => t . type === TokenType . ExportKeyword ) && ! dictionary . ExportableNodeTypes . includes ( stmt . type ) ) items . push ( {
264
264
message : 'This statement cannot be exported.' ,
265
- range : subRange ( stmt . range ) ,
265
+ range : subRange ( stmt . modifiers . find ( r => r . type === TokenType . ExportKeyword ) . range ) ,
266
266
severity : DiagnosticSeverity . Error ,
267
267
data : [
268
268
{
@@ -302,14 +302,14 @@ function sameNameCheck(statements: Statement[], filePath: string): Diagnostic[]
302
302
if ( statementIsA ( r , NodeType . Keyword ) ) return r as KeywordStatement ;
303
303
} ) . forEach ( stmt => {
304
304
305
- const n = stmt [ statementIsA ( stmt , NodeType . Keyword ) ? 'word' : 'name' ] ;
306
-
307
- if ( encounteredNames . includes ( n ) ) items . push ( {
308
- message : `Name '${ n } ' is already seen before.` ,
309
- range : subRange ( stmt . range ) ,
305
+ const n : IdentifierExpression = stmt [ statementIsA ( stmt , NodeType . Keyword ) ? 'word' : 'name' ] ;
306
+
307
+ if ( encounteredNames . includes ( n . value ) ) items . push ( {
308
+ message : `Name '${ n . value } ' is already seen before.` ,
309
+ range : subRange ( n . range ) ,
310
310
severity : DiagnosticSeverity . Error
311
311
} ) ;
312
- else encounteredNames . push ( n ) ;
312
+ else encounteredNames . push ( n . value ) ;
313
313
314
314
if ( statementIsA ( stmt , NodeType . Global ) ) c ( stmt . body ) ;
315
315
} ) ;
0 commit comments