2
2
3
3
import { workspace , TextDocument , Uri } from 'vscode' ;
4
4
import * as fs from "fs" ;
5
+ import * as path from "path" ;
5
6
6
- export function getFilePath ( text :string , document :TextDocument ) {
7
+ export function getFilePath ( text : string , document : TextDocument ) {
7
8
let paths = getFilePaths ( text , document ) ;
8
9
return paths . length > 0 ? paths [ 0 ] : null ;
9
10
}
10
11
11
- export function getFilePaths ( text :string , document :TextDocument ) : any {
12
+ export function getFilePaths ( text : string , document : TextDocument ) : any {
13
+ let paths = scanViewPaths ( document ) ;
12
14
let config = workspace . getConfiguration ( 'laravel_goto_view' ) ;
13
15
let workspaceFolder = workspace . getWorkspaceFolder ( document . uri ) . uri . fsPath ;
14
- text = text . replace ( / \" | \' / g, '' ) ;
16
+ text = text . replace ( / \" | \' / g, '' ) ;
15
17
let result = [ ] ;
16
18
if ( text . indexOf ( "::" ) != - 1 ) {
17
19
let info = text . split ( '::' ) ;
18
20
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 ] ;
20
22
let filePath = workspaceFolder + showPath ;
21
- if ( fs . existsSync ( filePath ) ) {
23
+ if ( fs . existsSync ( filePath ) ) {
22
24
result . push ( {
23
25
"name" : info [ 0 ] ,
24
26
"showPath" : showPath ,
@@ -27,11 +29,11 @@ export function getFilePaths(text:string, document:TextDocument): any {
27
29
}
28
30
}
29
31
} else {
30
- for ( let item in config . folders ) {
32
+ for ( let item in paths ) {
31
33
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 ] ;
33
35
let filePath = workspaceFolder + showPath ;
34
- if ( fs . existsSync ( filePath ) ) {
36
+ if ( fs . existsSync ( filePath ) ) {
35
37
result . push ( {
36
38
"name" : item ,
37
39
"showPath" : showPath ,
@@ -62,7 +64,17 @@ export function readText(uri: Uri) {
62
64
} ) ;
63
65
}
64
66
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 ;
68
80
}
0 commit comments