-
Notifications
You must be signed in to change notification settings - Fork 55
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
10 changed files
with
1,575 additions
and
1,516 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,87 +1,87 @@ | ||
'use strict'; | ||
|
||
import * as vscode from 'vscode'; | ||
import Helpers from './helpers'; | ||
|
||
|
||
export default class AuthProvider implements vscode.CompletionItemProvider { | ||
private abilities: Array<any> = []; | ||
private models: Array<any> = []; | ||
|
||
constructor () { | ||
var self = this; | ||
if (vscode.workspace.getConfiguration("LaravelExtraIntellisense").get<boolean>('disableAuth', false)) { | ||
return; | ||
} | ||
self.loadAbilities(); | ||
setInterval(function () { | ||
self.loadAbilities(); | ||
}, 60000); | ||
} | ||
|
||
provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext): Array<vscode.CompletionItem> { | ||
var out:Array<vscode.CompletionItem> = []; | ||
var func = Helpers.parseDocumentFunction(document, position); | ||
if (func === null) { | ||
return out; | ||
} | ||
|
||
if (func && ((func.class && Helpers.tags.auth.classes.some((cls:string) => func.class.includes(cls))) || Helpers.tags.auth.functions.some((fn:string) => func.function.includes(fn)))) { | ||
if (func.paramIndex === 1) { | ||
for (let i in this.models) { | ||
let completeItem = new vscode.CompletionItem(this.models[i].replace(/\\/, '\\\\'), vscode.CompletionItemKind.Value); | ||
completeItem.range = document.getWordRangeAtPosition(position, Helpers.wordMatchRegex); | ||
out.push(completeItem); | ||
} | ||
} else { | ||
for (let i in this.abilities) { | ||
let completeItem = new vscode.CompletionItem(this.abilities[i], vscode.CompletionItemKind.Value); | ||
completeItem.range = document.getWordRangeAtPosition(position, Helpers.wordMatchRegex); | ||
out.push(completeItem); | ||
} | ||
} | ||
} | ||
return out; | ||
} | ||
|
||
loadAbilities() { | ||
try { | ||
var self = this; | ||
Helpers.getModels().then((models) => self.models = models); | ||
Helpers.runLaravel(` | ||
echo json_encode( | ||
array_merge( | ||
array_keys(Illuminate\\Support\\Facades\\Gate::abilities()), | ||
array_values( | ||
array_filter( | ||
array_unique( | ||
Illuminate\\Support\\Arr::flatten( | ||
array_map( | ||
function ($val, $key) { | ||
return array_map( | ||
function ($rm) { | ||
return $rm->getName(); | ||
}, | ||
(new ReflectionClass($val))->getMethods() | ||
); | ||
}, | ||
Illuminate\\Support\\Facades\\Gate::policies(), | ||
array_keys(Illuminate\\Support\\Facades\\Gate::policies()) | ||
) | ||
) | ||
), | ||
function ($an) {return !in_array($an, ['allow', 'deny']);} | ||
) | ||
) | ||
) | ||
); | ||
` | ||
).then(function (result) { | ||
var abilities = JSON.parse(result); | ||
self.abilities = abilities; | ||
}); | ||
} catch (exception) { | ||
console.error(exception); | ||
} | ||
} | ||
} | ||
'use strict'; | ||
|
||
import * as vscode from 'vscode'; | ||
import Helpers from './helpers'; | ||
|
||
|
||
export default class AuthProvider implements vscode.CompletionItemProvider { | ||
private abilities: Array<any> = []; | ||
private models: Array<any> = []; | ||
|
||
constructor () { | ||
var self = this; | ||
if (vscode.workspace.getConfiguration("LaravelExtraIntellisense").get<boolean>('disableAuth', false)) { | ||
return; | ||
} | ||
self.loadAbilities(); | ||
setInterval(function () { | ||
self.loadAbilities(); | ||
}, 60000); | ||
} | ||
|
||
provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext): Array<vscode.CompletionItem> { | ||
var out:Array<vscode.CompletionItem> = []; | ||
var func = Helpers.parseDocumentFunction(document, position); | ||
if (func === null) { | ||
return out; | ||
} | ||
|
||
if (func && ((func.class && Helpers.tags.auth.classes.some((cls:string) => func.class.includes(cls))) || Helpers.tags.auth.functions.some((fn:string) => func.function.includes(fn)))) { | ||
if (func.paramIndex === 1) { | ||
for (let i in this.models) { | ||
let completeItem = new vscode.CompletionItem(this.models[i].replace(/\\/, '\\\\'), vscode.CompletionItemKind.Value); | ||
completeItem.range = document.getWordRangeAtPosition(position, Helpers.wordMatchRegex); | ||
out.push(completeItem); | ||
} | ||
} else { | ||
for (let i in this.abilities) { | ||
let completeItem = new vscode.CompletionItem(this.abilities[i], vscode.CompletionItemKind.Value); | ||
completeItem.range = document.getWordRangeAtPosition(position, Helpers.wordMatchRegex); | ||
out.push(completeItem); | ||
} | ||
} | ||
} | ||
return out; | ||
} | ||
|
||
loadAbilities() { | ||
try { | ||
var self = this; | ||
Helpers.getModels().then((models) => self.models = models); | ||
Helpers.runLaravel(` | ||
echo json_encode( | ||
array_merge( | ||
array_keys(Illuminate\\Support\\Facades\\Gate::abilities()), | ||
array_values( | ||
array_filter( | ||
array_unique( | ||
Illuminate\\Support\\Arr::flatten( | ||
array_map( | ||
function ($val, $key) { | ||
return array_map( | ||
function ($rm) { | ||
return $rm->getName(); | ||
}, | ||
(new ReflectionClass($val))->getMethods() | ||
); | ||
}, | ||
Illuminate\\Support\\Facades\\Gate::policies(), | ||
array_keys(Illuminate\\Support\\Facades\\Gate::policies()) | ||
) | ||
) | ||
), | ||
function ($an) {return !in_array($an, ['allow', 'deny']);} | ||
) | ||
) | ||
) | ||
); | ||
`, 'Auth Data' | ||
).then(function (result) { | ||
var abilities = JSON.parse(result); | ||
self.abilities = abilities; | ||
}); | ||
} catch (exception) { | ||
console.error(exception); | ||
} | ||
} | ||
} |
Oops, something went wrong.