11'use strict' ;
22
3- import * as fs from "fs" ;
4- import * as vscode from 'vscode ' ;
5- import Range = vscode . Range ;
3+ import { workspace , languages , Hover , ExtensionContext } from 'vscode' ;
4+ import { LinkProvider } from './link ' ;
5+ import * as util from './util' ;
66
7- export function activate ( context : vscode . ExtensionContext ) {
8- // console.log('Congratulations, your extension "laravel-goto-view" is now active!');
9- let disposable = vscode . commands . registerCommand ( 'extension.gotoView' , gotoView ) ;
10- context . subscriptions . push ( disposable ) ;
7+ const REG = / ( [ ' " ] ) [ ^ ' " ] * \1/ ;
8+
9+ export function activate ( context : ExtensionContext ) {
10+ let hover = languages . registerHoverProvider ( 'php' , {
11+ provideHover ( document , position , token ) {
12+ let linkRange = document . getWordRangeAtPosition ( position , REG ) ;
13+ if ( linkRange ) {
14+ let filePath = util . getFilePath ( document . getText ( linkRange ) ) ;
15+ if ( filePath != null ) {
16+ return new Hover ( filePath . replace ( workspace . rootPath + '/' , '' ) ) ;
17+ }
18+ }
19+ return ;
20+ }
21+ } ) ;
22+ let link = languages . registerDocumentLinkProvider ( [ 'php' ] , new LinkProvider ( ) ) ;
23+ context . subscriptions . push ( hover ) ;
24+ context . subscriptions . push ( link ) ;
1125}
1226
1327export function deactivate ( ) {
1428 //
15- }
16-
17- function gotoView ( ) {
18- let uri = vscode . Uri ;
19- let e = vscode . window . activeTextEditor ;
20- let d = e . document ;
21- let sel = e . selections ;
22-
23- let txt : string = d . getText ( new Range ( sel [ 0 ] . start , sel [ 0 ] . end ) ) ;
24- let path = vscode . workspace . rootPath + "/resources/views/" + txt . replace ( / \. / g, '/' ) + ".blade.php" ;
25-
26- fs . exists ( path , function ( exists ) {
27- exists ? vscode . window . showTextDocument ( uri . file ( path ) ) : vscode . window . showInformationMessage ( 'View does not exist!' ) ; ;
28- } ) ;
2929}
0 commit comments