1- import { extname , normalize } from 'path' ;
2- import { Diagnostic , DiagnosticSeverity } from 'vscode-languageserver' ;
1+ import { extname } from 'path' ;
2+ import { Diagnostic } from 'vscode-languageserver' ;
33import { TextDocument } from 'vscode-languageserver-textdocument' ;
44import { configService } from '../services/configuration.service' ;
55import { fileSystemService } from '../services/fs.service' ;
66import { imageFileExtensions } from 'shared' ;
7- import Parser , { Language } from 'tree-sitter' ;
8- import ccini from 'tree-sitter-ccini' ;
7+ import Parser , { Language , Query } from '@keqingmoe/ tree-sitter' ;
8+ import language from 'tree-sitter-ccini' ;
99
1010export function validateFilePaths ( textDocument : TextDocument ) : Diagnostic [ ] {
1111 // In this simple example we get the settings for every validate run.
@@ -15,44 +15,59 @@ export function validateFilePaths(textDocument: TextDocument): Diagnostic[] {
1515 const text = textDocument . getText ( ) ;
1616
1717 const parser = new Parser ( ) ;
18- parser . setLanguage ( ccini as Language ) ;
18+ parser . setLanguage ( language as Language ) ;
19+
20+ const queryString = `\
21+ (assignment
22+ key: (property) @key
23+ value: (modulePath
24+ extension: (fileExtension) @extension
25+ ) @modulePathValue
26+ ) @assignment` ;
27+
28+ const filepathQuery = new Query ( language as Language , queryString ) ;
1929
2030 const tree = parser . parse ( text ) ;
2131
22- let m : RegExpExecArray | null ;
32+ const captures = filepathQuery . captures ( tree . rootNode ) ;
2333
24- let problems = 0 ;
34+ const problems = 0 ;
2535 const diagnostics : Diagnostic [ ] = [ ] ;
2636
27- while (
28- ( m = pattern . exec ( text ) ) &&
29- problems < configService . globalSettings . maxNumberOfProblems
30- ) {
31- if ( ! checkIfPathExists ( normalizedPath ) ) {
32- problems ++ ;
33- const diagnostic : Diagnostic = {
34- severity : DiagnosticSeverity . Error ,
35- range : {
36- start : textDocument . positionAt ( m . index + m [ 1 ] . length ) ,
37- end : textDocument . positionAt ( m . index + m [ 0 ] . length ) ,
38- } ,
39- message : `Cannot find the file ${ m [ 2 ] } ` ,
40- source : 'CC Language Features' ,
41- } ;
42- if ( configService . hasDiagnosticRelatedInformationCapability ) {
43- diagnostic . relatedInformation = [
44- {
45- location : {
46- uri : textDocument . uri ,
47- range : Object . assign ( { } , diagnostic . range ) ,
48- } ,
49- message :
50- 'This may be due to a bad file extension/path, or incorrect capitalization.' ,
51- } ,
52- ] ;
53- }
54- diagnostics . push ( diagnostic ) ;
37+ for ( const capture of captures ) {
38+ if ( problems >= configService . globalSettings . maxNumberOfProblems ) {
39+ break ;
5540 }
41+
42+ console . log ( capture . name ) ;
43+ console . log ( capture . node . text ) ;
44+ const normalizedPath = capture . name ;
45+
46+ // if (!checkIfPathExists(normalizedPath)) {
47+ // problems++;
48+ // const diagnostic: Diagnostic = {
49+ // severity: DiagnosticSeverity.Error,
50+ // range: {
51+ // start: textDocument.positionAt(captures.index + captures[1].length),
52+ // end: textDocument.positionAt(captures.index + captures[0].length),
53+ // },
54+ // message: `Cannot find the file ${captures[2]}`,
55+ // source: 'CC Language Features',
56+ // };
57+ // if (configService.hasDiagnosticRelatedInformationCapability) {
58+ // diagnostic.relatedInformation = [
59+ // {
60+ // location: {
61+ // uri: textDocument.uri,
62+ // range: Object.assign({}, diagnostic.range),
63+ // },
64+ // message:
65+ // 'This may be due to a bad file extension/path, or incorrect capitalization.',
66+ // },
67+ // ];
68+ // }
69+ // diagnostics.push(diagnostic);
70+ // }
5671 }
5772
5873 // Send the computed diagnostics to VSCode.
0 commit comments