-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
180 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() { | ||
// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<DocumentLink[]> { | ||
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<DocumentLink[]> { | ||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |