Skip to content

Commit 624e957

Browse files
committed
🤔
1 parent 6ed4bca commit 624e957

File tree

4 files changed

+180
-170
lines changed

4 files changed

+180
-170
lines changed

‎package.json‎

Lines changed: 68 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,68 @@
1-
{
2-
"name": "laravel-goto-view",
3-
"displayName": "Laravel goto view",
4-
"description": "Quick jump to view",
5-
"version": "1.1.3",
6-
"publisher": "codingyu",
7-
"engines": {
8-
"vscode": "^1.19.0"
9-
},
10-
"icon": "images/icon.jpg",
11-
"bugs": {
12-
"url": "https://github.com/codingyu/laravel-goto-view/issues"
13-
},
14-
"homepage": "https://github.com/codingyu/laravel-goto-view/blob/master/README.md",
15-
"repository": {
16-
"type": "git",
17-
"url": "https://github.com/codingyu/laravel-goto-view.git"
18-
},
19-
"categories": [
20-
"Other"
21-
],
22-
"keywords":[
23-
"PHP",
24-
"Laravel"
25-
],
26-
"activationEvents": [
27-
"*"
28-
],
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-
{
43-
"name": "default",
44-
"path":"/resources/views"
45-
}
46-
],
47-
"items": {
48-
"type": "object",
49-
"required": [
50-
"name",
51-
"path"
52-
]
53-
},
54-
"minItems": 1,
55-
"uniqueItems": true,
56-
"description": "Multiple folders"
57-
}
58-
}
59-
}
60-
},
61-
"main": "./out/src/extension",
62-
"scripts": {
63-
"vscode:prepublish": "tsc -p ./",
64-
"compile": "tsc -watch -p ./",
65-
"postinstall": "node ./node_modules/vscode/bin/install",
66-
"test": "node ./node_modules/vscode/bin/test"
67-
},
68-
"devDependencies": {
69-
"typescript": "^2.0.3",
70-
"vscode": "^1.0.0",
71-
"mocha": "^2.3.3",
72-
"@types/node": "^6.0.40",
73-
"@types/mocha": "^2.2.32"
74-
}
75-
}
1+
{
2+
"name": "laravel-goto-view",
3+
"displayName": "Laravel goto view",
4+
"description": "Quick jump to view",
5+
"version": "1.1.3",
6+
"publisher": "codingyu",
7+
"engines": {
8+
"vscode": "^1.19.0"
9+
},
10+
"icon": "images/icon.jpg",
11+
"bugs": {
12+
"url": "https://github.com/codingyu/laravel-goto-view/issues"
13+
},
14+
"homepage": "https://github.com/codingyu/laravel-goto-view/blob/master/README.md",
15+
"repository": {
16+
"type": "git",
17+
"url": "https://github.com/codingyu/laravel-goto-view.git"
18+
},
19+
"categories": [
20+
"Other"
21+
],
22+
"keywords":[
23+
"PHP",
24+
"Laravel"
25+
],
26+
"activationEvents": [
27+
"*"
28+
],
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": "object",
41+
"default": {
42+
"default":"/resources/views"
43+
},
44+
"items": {
45+
"type": "string"
46+
},
47+
"minItems": 1,
48+
"uniqueItems": true,
49+
"description": "Multiple folders"
50+
}
51+
}
52+
}
53+
},
54+
"main": "./out/src/extension",
55+
"scripts": {
56+
"vscode:prepublish": "tsc -p ./",
57+
"compile": "tsc -watch -p ./",
58+
"postinstall": "node ./node_modules/vscode/bin/install",
59+
"test": "node ./node_modules/vscode/bin/test"
60+
},
61+
"devDependencies": {
62+
"typescript": "^2.0.3",
63+
"vscode": "^1.0.0",
64+
"mocha": "^2.3.3",
65+
"@types/node": "^6.0.40",
66+
"@types/mocha": "^2.2.32"
67+
}
68+
}

‎src/extension.ts‎

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
'use strict';
2-
3-
import { workspace, languages, Hover, ExtensionContext, MarkdownString, Uri} from 'vscode';
4-
import { LinkProvider } from './link';
5-
import * as util from './util';
6-
7-
const REG = /(['"])[^'"]*\1/;
8-
9-
export function activate(context: ExtensionContext) {
10-
let config = workspace.getConfiguration('laravel_goto_view');
11-
let hover = languages.registerHoverProvider(['php','blade','laravel-blade'], {
12-
provideHover(document, position, token) {
13-
let linkRange = document.getWordRangeAtPosition(position, REG);
14-
if(linkRange){
15-
let filePaths = util.getFilePaths(document.getText(linkRange), document);
16-
let workspaceFolder = workspace.getWorkspaceFolder(document.uri);
17-
if(filePaths.length > 0){
18-
let text:string = "";
19-
for (let i in filePaths) {
20-
text += `\`${filePaths[i].name}\` [${workspaceFolder.name + filePaths[i].showPath}](${filePaths[i].fileUri}) \r`;
21-
}
22-
return new Hover(new MarkdownString(text));
23-
}
24-
}
25-
return;
26-
}
27-
});
28-
context.subscriptions.push(hover);
29-
30-
if (config.quick_click) {
31-
let link = languages.registerDocumentLinkProvider(['php','blade','laravel-blade'], new LinkProvider());
32-
context.subscriptions.push(link);
33-
}
34-
}
35-
36-
export function deactivate() {
37-
//
1+
'use strict';
2+
3+
import { workspace, languages, Hover, ExtensionContext, MarkdownString, Uri} from 'vscode';
4+
import { LinkProvider } from './link';
5+
import * as util from './util';
6+
7+
const REG = /(['"])[^'"]*\1/;
8+
9+
export function activate(context: ExtensionContext) {
10+
let config = workspace.getConfiguration('laravel_goto_view');
11+
let hover = languages.registerHoverProvider(['php','blade','laravel-blade'], {
12+
provideHover(document, position, token) {
13+
let linkRange = document.getWordRangeAtPosition(position, REG);
14+
if(linkRange){
15+
let filePaths = util.getFilePaths(document.getText(linkRange), document);
16+
let workspaceFolder = workspace.getWorkspaceFolder(document.uri);
17+
if(filePaths.length > 0){
18+
let text:string = "";
19+
for (let i in filePaths) {
20+
text += `\`${filePaths[i].name}\` [${workspaceFolder.name + filePaths[i].showPath}](${filePaths[i].fileUri}) \r`;
21+
}
22+
return new Hover(new MarkdownString(text));
23+
}
24+
}
25+
return;
26+
}
27+
});
28+
context.subscriptions.push(hover);
29+
30+
if (config.quick_click) {
31+
let link = languages.registerDocumentLinkProvider(['php','blade','laravel-blade'], new LinkProvider());
32+
context.subscriptions.push(link);
33+
}
34+
}
35+
36+
export function deactivate() {
37+
//
3838
}

‎src/link.ts‎

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
'use strict';
2-
3-
import { workspace, Position, Range, CancellationToken, DocumentLink, DocumentLinkProvider, TextDocument, Uri, ProviderResult } from 'vscode';
4-
import * as util from './util';
5-
6-
export class LinkProvider implements DocumentLinkProvider {
7-
public provideDocumentLinks(document: TextDocument, token: CancellationToken): ProviderResult<DocumentLink[]> {
8-
let documentLinks = [];
9-
let index = 0;
10-
let reg = /(['"])[^'"]*\1/g;
11-
while (index < document.lineCount) {
12-
let line = document.lineAt(index);
13-
let result = line.text.match(reg);
14-
if (result != null) {
15-
for (let item of result) {
16-
let filePath = util.getFilePath(item, document);
17-
if(filePath != null){
18-
let start = new Position(line.lineNumber, line.text.indexOf(item) + 1);
19-
let end = start.translate(0, item.length - 2);
20-
let documentlink = new DocumentLink(new Range(start, end), Uri.file(filePath));
21-
documentLinks.push(documentlink);
22-
};
23-
}
24-
}
25-
index++;
26-
}
27-
return documentLinks;
28-
}
1+
'use strict';
2+
3+
import { workspace, Position, Range, CancellationToken, DocumentLink, DocumentLinkProvider, TextDocument, Uri, ProviderResult } from 'vscode';
4+
import * as util from './util';
5+
6+
export class LinkProvider implements DocumentLinkProvider {
7+
public provideDocumentLinks(document: TextDocument, token: CancellationToken): ProviderResult<DocumentLink[]> {
8+
let documentLinks = [];
9+
let index = 0;
10+
let reg = /(['"])[^'"]*\1/g;
11+
while (index < document.lineCount) {
12+
let line = document.lineAt(index);
13+
let result = line.text.match(reg);
14+
if (result != null) {
15+
for (let item of result) {
16+
let filePath = util.getFilePath(item, document);
17+
if(filePath != null){
18+
let start = new Position(line.lineNumber, line.text.indexOf(item) + 1);
19+
let end = start.translate(0, item.length - 2);
20+
let documentlink = new DocumentLink(new Range(start, end), Uri.file(filePath));
21+
documentLinks.push(documentlink);
22+
};
23+
}
24+
}
25+
index++;
26+
}
27+
return documentLinks;
28+
}
2929
}

‎src/util.ts‎

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,48 @@
1-
'use strict';
2-
3-
import { workspace, TextDocument, Uri } from 'vscode';
4-
import * as fs from "fs";
5-
6-
export function getFilePath(text:string, document:TextDocument) {
7-
let config = workspace.getConfiguration('laravel_goto_view');
8-
let filePath = workspace.getWorkspaceFolder(document.uri).uri.fsPath + config.folder[0].path + "/" + text.replace(/\./g,'/').replace(/\"|\'/g,'') + ".blade.php";
9-
if(fs.existsSync(filePath)){
10-
return filePath;
11-
}else{
12-
return null;
13-
}
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.path + "/" + 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({
24-
"name": item.name,
25-
"showPath": showPath,
26-
"fileUri": Uri.file(filePath)
27-
});
28-
}
29-
}
30-
return result;
1+
'use strict';
2+
3+
import { workspace, TextDocument, Uri } from 'vscode';
4+
import * as fs from "fs";
5+
6+
export function getFilePath(text:string, document:TextDocument) {
7+
let config = workspace.getConfiguration('laravel_goto_view');
8+
let workspaceFolder = workspace.getWorkspaceFolder(document.uri).uri.fsPath;
9+
let filePath = workspaceFolder + config.folder[0].path + "/" + text.replace(/\./g,'/').replace(/\"|\'/g,'') + ".blade.php";
10+
if(fs.existsSync(filePath)){
11+
return filePath;
12+
}else{
13+
return null;
14+
}
15+
}
16+
17+
export function getFilePaths(text:string, document:TextDocument): any {
18+
let config = workspace.getConfiguration('laravel_goto_view');
19+
let workspaceFolder = workspace.getWorkspaceFolder(document.uri).uri.fsPath;
20+
text = text.replace(/\"|\'/g,'');
21+
let result = [];
22+
if (text.indexOf("::") != -1) {
23+
let info = text.split('::');
24+
let showPath = config.folder[info[0]] + "/" + info[1].replace(/\./g,'/') + ".blade.php";
25+
let filePath = workspaceFolder + showPath;
26+
if(fs.existsSync(filePath)){
27+
result.push({
28+
"name": info[0],
29+
"showPath": showPath,
30+
"fileUri": Uri.file(filePath)
31+
});
32+
}
33+
} else {
34+
for (let item in config.folder) {
35+
let showPath = config.folder[item] + "/" + text.replace(/\./g,'/') + ".blade.php";
36+
let filePath = workspaceFolder + showPath;
37+
if(fs.existsSync(filePath)){
38+
result.push({
39+
"name": item,
40+
"showPath": showPath,
41+
"fileUri": Uri.file(filePath)
42+
});
43+
}
44+
}
45+
}
46+
47+
return result;
3148
}

0 commit comments

Comments
 (0)