@@ -6,6 +6,7 @@ import { globalState } from './state/state';
66import { checkYamlExtension , getFilePatterns , getOrCreateTerminal , updateYamlSchemaAssociations } from './utils/utils' ;
77import { watchTestFiles , discoverTests , registerTestProfiles } from './testExplorer/testExplorer' ;
88import { getAvailableDevices } from './utils/device' ;
9+ import * as fs from 'fs' ;
910
1011let deviceOutputChannel : vscode . OutputChannel ;
1112
@@ -37,50 +38,150 @@ export function activate(context: vscode.ExtensionContext) {
3738 { scheme : 'file' , language : 'yaml' } ,
3839 {
3940 async provideDocumentLinks ( document : vscode . TextDocument ) : Promise < vscode . DocumentLink [ ] > {
41+ console . log ( `\n=== Processing document: ${ document . uri . fsPath } ===` ) ;
4042 const links : vscode . DocumentLink [ ] = [ ] ;
4143 const text = document . getText ( ) ;
42- const runFlowRegex = / - ? \s * r u n F l o w : \s * (?: [ ' " ] ( [ ^ ' " ] + ) [ ' " ] | ( [ ^ \s ] + ) ) / g;
4344 const workspaceFolder = vscode . workspace . getWorkspaceFolder ( document . uri ) ;
4445
45- console . log ( 'Document text:' , text ) ;
46- console . log ( 'Looking for runFlow references...' ) ;
47-
4846 if ( ! workspaceFolder ) {
47+ console . log ( 'No workspace folder found, returning empty links' ) ;
4948 return links ;
5049 }
5150
51+ // Handle runFlow references
52+ console . log ( '\n--- Processing runFlow references ---' ) ;
53+ const runFlowRegex = / - ? \s * r u n F l o w : \s * (?: [ ' " ] ( [ ^ ' " ] + ) [ ' " ] | ( [ ^ \s ] + ) ) / g;
5254 let match ;
5355 while ( ( match = runFlowRegex . exec ( text ) ) !== null ) {
54- console . log ( 'Found match:' , match ) ;
5556 const filePath = match [ 1 ] || match [ 2 ] ;
57+ console . log ( `Found runFlow reference: "${ filePath } "` ) ;
58+
5659 const startPos = document . positionAt ( match . index ) ;
5760 const endPos = document . positionAt ( match . index + match [ 0 ] . length ) ;
61+ console . log ( `Position: ${ startPos . line } :${ startPos . character } to ${ endPos . line } :${ endPos . character } ` ) ;
5862
59- console . log ( 'File path:' , filePath ) ;
60- console . log ( 'Start position:' , startPos ) ;
61- console . log ( 'End position:' , endPos ) ;
62-
63- // Try to resolve the file path
6463 const targetPath = path . resolve ( path . dirname ( document . uri . fsPath ) , filePath ) ;
65- const targetUri = vscode . Uri . file ( targetPath ) ;
64+ console . log ( `Resolved target path: ${ targetPath } ` ) ;
65+
66+ if ( fs . existsSync ( targetPath ) ) {
67+ console . log ( 'Target file exists, creating link' ) ;
68+ links . push ( new vscode . DocumentLink (
69+ new vscode . Range ( startPos , endPos ) ,
70+ vscode . Uri . file ( targetPath )
71+ ) ) ;
72+ } else {
73+ console . log ( 'Target file does not exist, skipping link' ) ;
74+ }
75+ }
6676
67- console . log ( 'Target path:' , targetPath ) ;
77+ // Handle runScript references
78+ console . log ( '\n--- Processing runScript references ---' ) ;
79+ const runScriptRegex = / - ? \s * r u n S c r i p t : \s * (?: [ ' " ] ( [ ^ ' " ] + ) [ ' " ] | ( [ ^ \s ] + ) ) / g;
80+ while ( ( match = runScriptRegex . exec ( text ) ) !== null ) {
81+ const filePath = match [ 1 ] || match [ 2 ] ;
82+ console . log ( `Found runScript reference: "${ filePath } "` ) ;
83+
84+ const startPos = document . positionAt ( match . index ) ;
85+ const endPos = document . positionAt ( match . index + match [ 0 ] . length ) ;
86+ console . log ( `Position: ${ startPos . line } :${ startPos . character } to ${ endPos . line } :${ endPos . character } ` ) ;
6887
69- try {
70- await vscode . workspace . fs . stat ( targetUri ) ;
88+ const targetPath = path . resolve ( path . dirname ( document . uri . fsPath ) , filePath ) ;
89+ console . log ( `Resolved target path: ${ targetPath } ` ) ;
90+
91+ if ( fs . existsSync ( targetPath ) ) {
92+ console . log ( 'Target file exists, creating link' ) ;
7193 links . push ( new vscode . DocumentLink (
7294 new vscode . Range ( startPos , endPos ) ,
73- targetUri
95+ vscode . Uri . file ( targetPath )
7496 ) ) ;
75- console . log ( 'Added link for:' , targetPath ) ;
76- } catch ( error ) {
77- console . log ( 'File not found:' , targetPath ) ;
78- // File doesn't exist, skip this link
97+ } else {
98+ console . log ( 'Target file does not exist, skipping link' ) ;
99+ }
100+ }
101+
102+ // Handle addMedia references (both array and object formats)
103+ console . log ( '\n--- Processing addMedia references ---' ) ;
104+ const addMediaRegex = / - ? \s * a d d M e d i a : \s * (?: [ ' " ] ( [ ^ ' " ] + ) [ ' " ] | ( [ ^ \s ] + ) | ( \[ .* ?\] ) | ( { .* ?} ) ) / g;
105+ while ( ( match = addMediaRegex . exec ( text ) ) !== null ) {
106+ const filePath = match [ 1 ] || match [ 2 ] || match [ 3 ] || match [ 4 ] ;
107+ if ( ! filePath ) {
108+ console . log ( 'No file path found in addMedia match, skipping' ) ;
79109 continue ;
80110 }
111+
112+ console . log ( `Found addMedia reference: "${ filePath } "` ) ;
113+ const startPos = document . positionAt ( match . index ) ;
114+ const endPos = document . positionAt ( match . index + match [ 0 ] . length ) ;
115+ console . log ( `Position: ${ startPos . line } :${ startPos . character } to ${ endPos . line } :${ endPos . character } ` ) ;
116+
117+ // Handle array format
118+ if ( filePath . startsWith ( '[' ) && filePath . endsWith ( ']' ) ) {
119+ console . log ( 'Processing array format addMedia' ) ;
120+ try {
121+ const mediaFiles = JSON . parse ( filePath ) ;
122+ console . log ( `Parsed media files array: ${ JSON . stringify ( mediaFiles ) } ` ) ;
123+ mediaFiles . forEach ( ( mediaFile : string ) => {
124+ const targetPath = path . resolve ( path . dirname ( document . uri . fsPath ) , mediaFile ) ;
125+ console . log ( `Resolved target path: ${ targetPath } ` ) ;
126+ if ( fs . existsSync ( targetPath ) ) {
127+ console . log ( 'Target file exists, creating link' ) ;
128+ links . push ( new vscode . DocumentLink (
129+ new vscode . Range ( startPos , endPos ) ,
130+ vscode . Uri . file ( targetPath )
131+ ) ) ;
132+ } else {
133+ console . log ( 'Target file does not exist, skipping link' ) ;
134+ }
135+ } ) ;
136+ } catch ( error ) {
137+ console . error ( 'Failed to parse addMedia array:' , error ) ;
138+ }
139+ }
140+ // Handle object format with files property
141+ else if ( filePath . startsWith ( '{' ) && filePath . endsWith ( '}' ) ) {
142+ console . log ( 'Processing object format addMedia' ) ;
143+ try {
144+ const mediaObj = JSON . parse ( filePath ) ;
145+ console . log ( `Parsed media object: ${ JSON . stringify ( mediaObj ) } ` ) ;
146+ if ( mediaObj . files && Array . isArray ( mediaObj . files ) ) {
147+ mediaObj . files . forEach ( ( mediaFile : string ) => {
148+ const targetPath = path . resolve ( path . dirname ( document . uri . fsPath ) , mediaFile ) ;
149+ console . log ( `Resolved target path: ${ targetPath } ` ) ;
150+ if ( fs . existsSync ( targetPath ) ) {
151+ console . log ( 'Target file exists, creating link' ) ;
152+ links . push ( new vscode . DocumentLink (
153+ new vscode . Range ( startPos , endPos ) ,
154+ vscode . Uri . file ( targetPath )
155+ ) ) ;
156+ } else {
157+ console . log ( 'Target file does not exist, skipping link' ) ;
158+ }
159+ } ) ;
160+ } else {
161+ console . log ( 'No files array found in media object' ) ;
162+ }
163+ } catch ( error ) {
164+ console . error ( 'Failed to parse addMedia object:' , error ) ;
165+ }
166+ }
167+ // Handle single file format
168+ else {
169+ console . log ( 'Processing single file format addMedia' ) ;
170+ const targetPath = path . resolve ( path . dirname ( document . uri . fsPath ) , filePath ) ;
171+ console . log ( `Resolved target path: ${ targetPath } ` ) ;
172+ if ( fs . existsSync ( targetPath ) ) {
173+ console . log ( 'Target file exists, creating link' ) ;
174+ links . push ( new vscode . DocumentLink (
175+ new vscode . Range ( startPos , endPos ) ,
176+ vscode . Uri . file ( targetPath )
177+ ) ) ;
178+ } else {
179+ console . log ( 'Target file does not exist, skipping link' ) ;
180+ }
181+ }
81182 }
82183
83- console . log ( ' Total links found:' , links . length ) ;
184+ console . log ( `\n=== Total links created: ${ links . length } ===\n` ) ;
84185 return links ;
85186 }
86187 }
0 commit comments