Skip to content

Commit 73b0d8e

Browse files
committed
Add configuration
1 parent 1af055b commit 73b0d8e

File tree

3 files changed

+58
-10
lines changed

3 files changed

+58
-10
lines changed

package.json

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"version": "1.1.3",
66
"publisher": "codingyu",
77
"engines": {
8-
"vscode": "^1.15.0"
8+
"vscode": "^1.19.0"
99
},
1010
"icon": "images/icon.jpg",
1111
"bugs": {
@@ -26,6 +26,31 @@
2626
"activationEvents": [
2727
"*"
2828
],
29+
"contributes": {
30+
"configuration": {
31+
"type": "object",
32+
"title": "Laravel goto view configuration",
33+
"properties": {
34+
"laravel_goto_view.quick_click": {
35+
"type": "boolean",
36+
"default": true,
37+
"description": "Use 'Ctrl' or 'Alt' + click"
38+
},
39+
"laravel_goto_view.folder": {
40+
"type": "array",
41+
"default": [
42+
"/resources/views"
43+
],
44+
"items": {
45+
"type": "string"
46+
},
47+
"minItems": 1,
48+
"uniqueItems": true,
49+
"description": "Multiple folders"
50+
}
51+
}
52+
}
53+
},
2954
"main": "./out/src/extension",
3055
"scripts": {
3156
"vscode:prepublish": "tsc -p ./",

src/extension.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
11
'use strict';
22

3-
import { workspace, languages, Hover, ExtensionContext} from 'vscode';
3+
import { workspace, languages, Hover, ExtensionContext, MarkdownString, Uri} from 'vscode';
44
import { LinkProvider } from './link';
55
import * as util from './util';
66

77
const REG = /(['"])[^'"]*\1/;
88

99
export function activate(context: ExtensionContext) {
10+
let config = workspace.getConfiguration('laravel_goto_view');
1011
let hover = languages.registerHoverProvider(['php','blade','laravel-blade'], {
1112
provideHover(document, position, token) {
1213
let linkRange = document.getWordRangeAtPosition(position, REG);
1314
if(linkRange){
14-
let filePath = util.getFilePath(document.getText(linkRange), document);
15+
let filePaths = util.getFilePaths(document.getText(linkRange), document);
1516
let workspaceFolder = workspace.getWorkspaceFolder(document.uri);
16-
if(filePath != null){
17-
return new Hover(workspaceFolder.name + filePath.replace(workspaceFolder.uri.fsPath,''));
17+
if(filePaths.length > 0){
18+
let text:string = "";
19+
for (let i in filePaths) {
20+
text += i == '0' ? `- \`Default\`` : `- \`Other\``;
21+
text += ` [${workspaceFolder.name + filePaths[i].showPath}](${filePaths[i].fileUri})\n`;
22+
}
23+
return new Hover(new MarkdownString(text));
1824
}
1925
}
2026
return;
2127
}
2228
});
23-
let link = languages.registerDocumentLinkProvider(['php','blade','laravel-blade'], new LinkProvider());
24-
context.subscriptions.push(hover);
25-
context.subscriptions.push(link);
29+
context.subscriptions.push(hover);
30+
31+
if (config.quick_click) {
32+
let link = languages.registerDocumentLinkProvider(['php','blade','laravel-blade'], new LinkProvider());
33+
context.subscriptions.push(link);
34+
}
2635
}
2736

2837
export function deactivate() {

src/util.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
'use strict';
22

3-
import { workspace, TextDocument } from 'vscode';
3+
import { workspace, TextDocument, Uri } from 'vscode';
44
import * as fs from "fs";
55

66
export function getFilePath(text:string, document:TextDocument) {
7-
let filePath = workspace.getWorkspaceFolder(document.uri).uri.fsPath + "/resources/views/" + text.replace(/\./g,'/').replace(/\"|\'/g,'') + ".blade.php";
7+
let config = workspace.getConfiguration('laravel_goto_view');
8+
let filePath = workspace.getWorkspaceFolder(document.uri).uri.fsPath + config.folder[0] + "/" + text.replace(/\./g,'/').replace(/\"|\'/g,'') + ".blade.php";
89
if(fs.existsSync(filePath)){
910
return filePath;
1011
}else{
1112
return null;
1213
}
14+
}
15+
16+
export function getFilePaths(text:string, document:TextDocument): any {
17+
let config = workspace.getConfiguration('laravel_goto_view');
18+
let result = [];
19+
for (let item of config.folder) {
20+
let showPath = item + "/" + text.replace(/\./g,'/').replace(/\"|\'/g,'') + ".blade.php";
21+
let filePath = workspace.getWorkspaceFolder(document.uri).uri.fsPath + showPath;
22+
if(fs.existsSync(filePath)){
23+
result.push({"showPath": showPath, "fileUri": Uri.file(filePath)});
24+
}
25+
}
26+
return result;
1327
}

0 commit comments

Comments
 (0)