22
33import { workspace , TextDocument , Uri } from 'vscode' ;
44import * as fs from "fs" ;
5+ import * as path from "path" ;
56
6- export function getFilePath ( text :string , document :TextDocument ) {
7+ export function getFilePath ( text : string , document : TextDocument ) {
78 let paths = getFilePaths ( text , document ) ;
89 return paths . length > 0 ? paths [ 0 ] : null ;
910}
1011
11- export function getFilePaths ( text :string , document :TextDocument ) : any {
12+ export function getFilePaths ( text : string , document : TextDocument ) : any {
13+ let paths = scanViewPaths ( document ) ;
1214 let config = workspace . getConfiguration ( 'laravel_goto_view' ) ;
1315 let workspaceFolder = workspace . getWorkspaceFolder ( document . uri ) . uri . fsPath ;
14- text = text . replace ( / \" | \' / g, '' ) ;
16+ text = text . replace ( / \" | \' / g, '' ) ;
1517 let result = [ ] ;
1618 if ( text . indexOf ( "::" ) != - 1 ) {
1719 let info = text . split ( '::' ) ;
1820 for ( let extension in config . extensions ) {
19- let showPath = config . folders [ info [ 0 ] ] + "/" + info [ 1 ] . replace ( / \. / g, '/' ) + config . extensions [ extension ] ;
21+ let showPath = paths [ info [ 0 ] ] + "/" + info [ 1 ] . replace ( / \. / g, '/' ) + config . extensions [ extension ] ;
2022 let filePath = workspaceFolder + showPath ;
21- if ( fs . existsSync ( filePath ) ) {
23+ if ( fs . existsSync ( filePath ) ) {
2224 result . push ( {
2325 "name" : info [ 0 ] ,
2426 "showPath" : showPath ,
@@ -27,11 +29,11 @@ export function getFilePaths(text:string, document:TextDocument): any {
2729 }
2830 }
2931 } else {
30- for ( let item in config . folders ) {
32+ for ( let item in paths ) {
3133 for ( let extension in config . extensions ) {
32- let showPath = config . folders [ item ] + "/" + text . replace ( / \. / g, '/' ) + config . extensions [ extension ] ;
34+ let showPath = paths [ item ] + "/" + text . replace ( / \. / g, '/' ) + config . extensions [ extension ] ;
3335 let filePath = workspaceFolder + showPath ;
34- if ( fs . existsSync ( filePath ) ) {
36+ if ( fs . existsSync ( filePath ) ) {
3537 result . push ( {
3638 "name" : item ,
3739 "showPath" : showPath ,
@@ -62,7 +64,17 @@ export function readText(uri: Uri) {
6264 } ) ;
6365}
6466
65- export function scanViewPaths ( ) {
66- let config = workspace . getConfiguration ( 'laravel_goto_view' ) ;
67- console . log ( config . folders ) ;
67+ export function scanViewPaths ( document : TextDocument ) {
68+ let configFolders = workspace . getConfiguration ( 'laravel_goto_view.folders' ) ;
69+ let folders = { } ;
70+ Object . assign ( folders , configFolders ) ;
71+ let workspaceFolder = workspace . getWorkspaceFolder ( document . uri ) . uri . fsPath ;
72+ let modulePath = path . join ( workspaceFolder , 'Modules' ) ;
73+ fs . readdirSync ( modulePath ) . forEach ( element => {
74+ let file = path . join ( modulePath , element ) ;
75+ if ( fs . statSync ( file ) . isDirectory ( ) ) {
76+ folders [ element . toLocaleLowerCase ( ) ] = "/Modules/" + element + "/resources/views" ;
77+ }
78+ } ) ;
79+ return folders ;
6880}
0 commit comments