diff --git a/package.json b/package.json index 81cf27c..02dfc00 100644 --- a/package.json +++ b/package.json @@ -1,75 +1,68 @@ -{ - "name": "laravel-goto-view", - "displayName": "Laravel goto view", - "description": "Quick jump to view", - "version": "1.1.3", - "publisher": "codingyu", - "engines": { - "vscode": "^1.19.0" - }, - "icon": "images/icon.jpg", - "bugs": { - "url": "https://github.com/codingyu/laravel-goto-view/issues" - }, - "homepage": "https://github.com/codingyu/laravel-goto-view/blob/master/README.md", - "repository": { - "type": "git", - "url": "https://github.com/codingyu/laravel-goto-view.git" - }, - "categories": [ - "Other" - ], - "keywords":[ - "PHP", - "Laravel" - ], - "activationEvents": [ - "*" - ], - "contributes": { - "configuration": { - "type": "object", - "title": "Laravel goto view configuration", - "properties": { - "laravel_goto_view.quick_click": { - "type": "boolean", - "default": true, - "description": "Use 'Ctrl' or 'Alt' + click" - }, - "laravel_goto_view.folder": { - "type": "array", - "default": [ - { - "name": "default", - "path":"/resources/views" - } - ], - "items": { - "type": "object", - "required": [ - "name", - "path" - ] - }, - "minItems": 1, - "uniqueItems": true, - "description": "Multiple folders" - } - } - } - }, - "main": "./out/src/extension", - "scripts": { - "vscode:prepublish": "tsc -p ./", - "compile": "tsc -watch -p ./", - "postinstall": "node ./node_modules/vscode/bin/install", - "test": "node ./node_modules/vscode/bin/test" - }, - "devDependencies": { - "typescript": "^2.0.3", - "vscode": "^1.0.0", - "mocha": "^2.3.3", - "@types/node": "^6.0.40", - "@types/mocha": "^2.2.32" - } -} +{ + "name": "laravel-goto-view", + "displayName": "Laravel goto view", + "description": "Quick jump to view", + "version": "1.1.3", + "publisher": "codingyu", + "engines": { + "vscode": "^1.19.0" + }, + "icon": "images/icon.jpg", + "bugs": { + "url": "https://github.com/codingyu/laravel-goto-view/issues" + }, + "homepage": "https://github.com/codingyu/laravel-goto-view/blob/master/README.md", + "repository": { + "type": "git", + "url": "https://github.com/codingyu/laravel-goto-view.git" + }, + "categories": [ + "Other" + ], + "keywords":[ + "PHP", + "Laravel" + ], + "activationEvents": [ + "*" + ], + "contributes": { + "configuration": { + "type": "object", + "title": "Laravel goto view configuration", + "properties": { + "laravel_goto_view.quick_click": { + "type": "boolean", + "default": true, + "description": "Use 'Ctrl' or 'Alt' + click" + }, + "laravel_goto_view.folder": { + "type": "object", + "default": { + "default":"/resources/views" + }, + "items": { + "type": "string" + }, + "minItems": 1, + "uniqueItems": true, + "description": "Multiple folders" + } + } + } + }, + "main": "./out/src/extension", + "scripts": { + "vscode:prepublish": "tsc -p ./", + "compile": "tsc -watch -p ./", + "postinstall": "node ./node_modules/vscode/bin/install", + "test": "node ./node_modules/vscode/bin/test" + }, + "devDependencies": { + "typescript": "^2.0.3", + "vscode": "^1.0.0", + "mocha": "^2.3.3", + "@types/node": "^6.0.40", + "@types/mocha": "^2.2.32" + } +} diff --git a/src/extension.ts b/src/extension.ts index b952f02..38ee58e 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,38 +1,38 @@ -'use strict'; - -import { workspace, languages, Hover, ExtensionContext, MarkdownString, Uri} from 'vscode'; -import { LinkProvider } from './link'; -import * as util from './util'; - -const REG = /(['"])[^'"]*\1/; - -export function activate(context: ExtensionContext) { - let config = workspace.getConfiguration('laravel_goto_view'); - let hover = languages.registerHoverProvider(['php','blade','laravel-blade'], { - provideHover(document, position, token) { - let linkRange = document.getWordRangeAtPosition(position, REG); - if(linkRange){ - let filePaths = util.getFilePaths(document.getText(linkRange), document); - let workspaceFolder = workspace.getWorkspaceFolder(document.uri); - if(filePaths.length > 0){ - let text:string = ""; - for (let i in filePaths) { - text += `\`${filePaths[i].name}\` [${workspaceFolder.name + filePaths[i].showPath}](${filePaths[i].fileUri}) \r`; - } - return new Hover(new MarkdownString(text)); - } - } - return; - } - }); - context.subscriptions.push(hover); - - if (config.quick_click) { - let link = languages.registerDocumentLinkProvider(['php','blade','laravel-blade'], new LinkProvider()); - context.subscriptions.push(link); - } -} - -export function deactivate() { - // +'use strict'; + +import { workspace, languages, Hover, ExtensionContext, MarkdownString, Uri} from 'vscode'; +import { LinkProvider } from './link'; +import * as util from './util'; + +const REG = /(['"])[^'"]*\1/; + +export function activate(context: ExtensionContext) { + let config = workspace.getConfiguration('laravel_goto_view'); + let hover = languages.registerHoverProvider(['php','blade','laravel-blade'], { + provideHover(document, position, token) { + let linkRange = document.getWordRangeAtPosition(position, REG); + if(linkRange){ + let filePaths = util.getFilePaths(document.getText(linkRange), document); + let workspaceFolder = workspace.getWorkspaceFolder(document.uri); + if(filePaths.length > 0){ + let text:string = ""; + for (let i in filePaths) { + text += `\`${filePaths[i].name}\` [${workspaceFolder.name + filePaths[i].showPath}](${filePaths[i].fileUri}) \r`; + } + return new Hover(new MarkdownString(text)); + } + } + return; + } + }); + context.subscriptions.push(hover); + + if (config.quick_click) { + let link = languages.registerDocumentLinkProvider(['php','blade','laravel-blade'], new LinkProvider()); + context.subscriptions.push(link); + } +} + +export function deactivate() { + // } \ No newline at end of file diff --git a/src/link.ts b/src/link.ts index 482e15e..0eec86e 100644 --- a/src/link.ts +++ b/src/link.ts @@ -1,29 +1,29 @@ -'use strict'; - -import { workspace, Position, Range, CancellationToken, DocumentLink, DocumentLinkProvider, TextDocument, Uri, ProviderResult } from 'vscode'; -import * as util from './util'; - -export class LinkProvider implements DocumentLinkProvider { - public provideDocumentLinks(document: TextDocument, token: CancellationToken): ProviderResult { - let documentLinks = []; - let index = 0; - let reg = /(['"])[^'"]*\1/g; - while (index < document.lineCount) { - let line = document.lineAt(index); - let result = line.text.match(reg); - if (result != null) { - for (let item of result) { - let filePath = util.getFilePath(item, document); - if(filePath != null){ - let start = new Position(line.lineNumber, line.text.indexOf(item) + 1); - let end = start.translate(0, item.length - 2); - let documentlink = new DocumentLink(new Range(start, end), Uri.file(filePath)); - documentLinks.push(documentlink); - }; - } - } - index++; - } - return documentLinks; - } +'use strict'; + +import { workspace, Position, Range, CancellationToken, DocumentLink, DocumentLinkProvider, TextDocument, Uri, ProviderResult } from 'vscode'; +import * as util from './util'; + +export class LinkProvider implements DocumentLinkProvider { + public provideDocumentLinks(document: TextDocument, token: CancellationToken): ProviderResult { + let documentLinks = []; + let index = 0; + let reg = /(['"])[^'"]*\1/g; + while (index < document.lineCount) { + let line = document.lineAt(index); + let result = line.text.match(reg); + if (result != null) { + for (let item of result) { + let filePath = util.getFilePath(item, document); + if(filePath != null){ + let start = new Position(line.lineNumber, line.text.indexOf(item) + 1); + let end = start.translate(0, item.length - 2); + let documentlink = new DocumentLink(new Range(start, end), Uri.file(filePath)); + documentLinks.push(documentlink); + }; + } + } + index++; + } + return documentLinks; + } } \ No newline at end of file diff --git a/src/util.ts b/src/util.ts index 2d61e9b..0abfeef 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,31 +1,48 @@ -'use strict'; - -import { workspace, TextDocument, Uri } from 'vscode'; -import * as fs from "fs"; - -export function getFilePath(text:string, document:TextDocument) { - let config = workspace.getConfiguration('laravel_goto_view'); - let filePath = workspace.getWorkspaceFolder(document.uri).uri.fsPath + config.folder[0].path + "/" + text.replace(/\./g,'/').replace(/\"|\'/g,'') + ".blade.php"; - if(fs.existsSync(filePath)){ - return filePath; - }else{ - return null; - } -} - -export function getFilePaths(text:string, document:TextDocument): any { - let config = workspace.getConfiguration('laravel_goto_view'); - let result = []; - for (let item of config.folder) { - let showPath = item.path + "/" + text.replace(/\./g,'/').replace(/\"|\'/g,'') + ".blade.php"; - let filePath = workspace.getWorkspaceFolder(document.uri).uri.fsPath + showPath; - if(fs.existsSync(filePath)){ - result.push({ - "name": item.name, - "showPath": showPath, - "fileUri": Uri.file(filePath) - }); - } - } - return result; +'use strict'; + +import { workspace, TextDocument, Uri } from 'vscode'; +import * as fs from "fs"; + +export function getFilePath(text:string, document:TextDocument) { + let config = workspace.getConfiguration('laravel_goto_view'); + let workspaceFolder = workspace.getWorkspaceFolder(document.uri).uri.fsPath; + let filePath = workspaceFolder + config.folder[0].path + "/" + text.replace(/\./g,'/').replace(/\"|\'/g,'') + ".blade.php"; + if(fs.existsSync(filePath)){ + return filePath; + }else{ + return null; + } +} + +export function getFilePaths(text:string, document:TextDocument): any { + let config = workspace.getConfiguration('laravel_goto_view'); + let workspaceFolder = workspace.getWorkspaceFolder(document.uri).uri.fsPath; + text = text.replace(/\"|\'/g,''); + let result = []; + if (text.indexOf("::") != -1) { + let info = text.split('::'); + let showPath = config.folder[info[0]] + "/" + info[1].replace(/\./g,'/') + ".blade.php"; + let filePath = workspaceFolder + showPath; + if(fs.existsSync(filePath)){ + result.push({ + "name": info[0], + "showPath": showPath, + "fileUri": Uri.file(filePath) + }); + } + } else { + for (let item in config.folder) { + let showPath = config.folder[item] + "/" + text.replace(/\./g,'/') + ".blade.php"; + let filePath = workspaceFolder + showPath; + if(fs.existsSync(filePath)){ + result.push({ + "name": item, + "showPath": showPath, + "fileUri": Uri.file(filePath) + }); + } + } + } + + return result; } \ No newline at end of file