Pushing Extension
This commit is contained in:
commit
158cef5d3d
7 changed files with 699 additions and 0 deletions
34
.vscode/launch.json
vendored
Normal file
34
.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
// Use IntelliSense to learn about possible Node.js debug attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"name": "Lancer l'extension",
|
||||
"runtimeExecutable": "${execPath}",
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceRoot}"
|
||||
],
|
||||
"sourceMaps": true,
|
||||
"outFiles": [
|
||||
"${workspaceRoot}/out/**/*.js"
|
||||
],
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Lancer le programme",
|
||||
"program": "${workspaceRoot}/out/src"
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "attach",
|
||||
"name": "Attacher au port",
|
||||
"address": "localhost",
|
||||
"port": 5858
|
||||
}
|
||||
]
|
||||
}
|
31
README.md
Normal file
31
README.md
Normal file
|
@ -0,0 +1,31 @@
|
|||
# PocketMine-IDE
|
||||
|
||||
Add all pocketmine functions & classes from a src. Based on [https://github.com/bschulte/PHP-Autocomplete](https://github.com/bschulte/PHP-Autocomplete)
|
||||
|
||||
## Features
|
||||
|
||||
1. Allows an automatic class completion.
|
||||
2. Allows an automatic accessible function completion.
|
||||
|
||||
## Requirements
|
||||
|
||||
None
|
||||
|
||||
## Extension Settings
|
||||
|
||||
Set the library/pocketmine path (must not be compiled as .phar) in the settings and reload using command "Index PHP files".
|
||||
This will include and parse the new library
|
||||
|
||||
## Known Issues
|
||||
|
||||
None so far
|
||||
|
||||
## Release Notes
|
||||
## 0.0.1
|
||||
|
||||
Initial release.
|
||||
|
||||
## Links
|
||||
|
||||
|
||||
-----------------------------------------------------------------------------------------------------------
|
BIN
icon.png
Normal file
BIN
icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
320
out/src/extension.js
Normal file
320
out/src/extension.js
Normal file
|
@ -0,0 +1,320 @@
|
|||
'use strict';
|
||||
// The module 'vscode' contains the VS Code extensibility API
|
||||
// Import the module and reference it with the alias vscode in your code below
|
||||
const vscode = require('vscode');
|
||||
const phpMode_1 = require('./phpMode');
|
||||
const phpFunctionSuggestions_1 = require('./phpFunctionSuggestions');
|
||||
exports.phpFileFunctions = {};
|
||||
exports.phpFileStaticFunctions = {};
|
||||
exports.phpFileUses = {};
|
||||
exports.PHP_MODE = { language: 'php', scheme: 'file' };
|
||||
// this method is called when your extension is activated
|
||||
// your extension is activated the very first time the command is executed
|
||||
function activate(context) {
|
||||
// Do the initial indexing
|
||||
indexPhpFiles();
|
||||
console.log(exports.phpFileFunctions);
|
||||
console.log(Object.keys(exports.phpFileUses));
|
||||
vscode.workspace.onDidSaveTextDocument(function(document) {
|
||||
indexPhpFiles();
|
||||
});
|
||||
// Setup our class as a compvarion item provider for function autocompvare
|
||||
context.subscriptions.push(vscode.languages.registerCompletionItemProvider(phpMode_1.PHP_MODE, {
|
||||
provideCompletionItems(document, position, token) {
|
||||
var filename = document.fileName;
|
||||
var lineText = document.lineAt(position.line).text;
|
||||
var lineTillCurrentPosition = lineText.substr(0, position.character);
|
||||
var wordAtPosition = document.getWordRangeAtPosition(position);
|
||||
var currentWord = '';
|
||||
if (wordAtPosition && wordAtPosition.start.character < position.character) {
|
||||
var word = document.getText(wordAtPosition);
|
||||
currentWord = word.substr(0, position.character - wordAtPosition.start.character);
|
||||
}
|
||||
|
||||
var clas = /new\s+(\\)?(\w+)(\\\w+)*/.exec(lineText);
|
||||
var use = /use\s+(\w+)(\\\w+)*/.exec(lineText);
|
||||
var execute = /->(\w+)/.exec(lineText);
|
||||
var executeStatic = /::(\w+)/.exec(lineText);
|
||||
// Check through the list of functions that are included in this file and see if any match
|
||||
// the starting varter of the word we have so far
|
||||
var suggestions = [];
|
||||
// Check what files the current document includes/requires
|
||||
var currentFileName = document.uri.fsPath.replace(vscode.workspace.rootPath, '').slice(1);
|
||||
var currentPath = document.uri.fsPath.replace(vscode.workspace.rootPath, '').replace("src/", "");
|
||||
// Look through all included/required files for the current document
|
||||
for (var f in exports.phpFileFunctions) {
|
||||
// Checking normal functions
|
||||
if (execute)
|
||||
for (var func in exports.phpFileFunctions[f]) {
|
||||
func = exports.phpFileFunctions[f][func];
|
||||
if (func.function.indexOf(currentWord) > 0 && execute[1] == currentWord && (func.functionModifiers["public"] || f == currentPath)) {
|
||||
var newSuggestion = new vscode.CompletionItem(func.function, vscode.CompletionItemKind.Function);
|
||||
params = func.params;
|
||||
var parameters = [];
|
||||
params.forEach(function(value, key) {
|
||||
if (value) {
|
||||
params[key] = "$" + value[1];
|
||||
parameters[key] = (typeof value[2] !== "undefined" ? value[2] + " " : "") + value[1];
|
||||
parameters[key] += typeof value[3] !== "undefined" ? " = " + value[3] : "";
|
||||
}
|
||||
});
|
||||
newSuggestion.insertText = func.function+"(" + params.join(", ") + ")";
|
||||
newSuggestion.documentation = func.comment;
|
||||
newSuggestion.detail = "(" + parameters.join(", ") + ")";
|
||||
suggestions.push(newSuggestion);
|
||||
}
|
||||
};
|
||||
// Checking static functions
|
||||
if (executeStatic)
|
||||
for (var func in exports.phpFileStaticFunctions[f]) {
|
||||
func = exports.phpFileStaticFunctions[f][func];
|
||||
if (func.function.indexOf(currentWord) > 0 && executeStatic[1] == currentWord) {
|
||||
var newSuggestion = new vscode.CompletionItem(func.function, vscode.CompletionItemKind.Function);
|
||||
var params = func.params;
|
||||
var parameters = [];
|
||||
params.forEach(function(value, key) {
|
||||
if (value) {
|
||||
params[key] = "$" + value[1];
|
||||
parameters[key] = (typeof value[2] !== "undefined" ? value[2] + " " : "") + value[1];
|
||||
parameters[key] += typeof value[3] !== "undefined" ? " = " + value[3] : "";
|
||||
}
|
||||
})
|
||||
newSuggestion.insertText = func.function+"(" + params.join(", ") + ")";
|
||||
newSuggestion.documentation = func.comment;
|
||||
newSuggestion.detail = "(" + parameters.join(", ") + ")";
|
||||
suggestions.push(newSuggestion);
|
||||
}
|
||||
};
|
||||
if (f.indexOf(currentWord) > 0) {
|
||||
if (clas && (clas[2] == currentWord || clas[3] == "\\" + currentWord)) { // New instance
|
||||
var currentClass = f.substr(0, f.length - 4).replace(new RegExp("\/", "g"), "\\");
|
||||
var params = [];
|
||||
if (typeof exports.phpFileFunctions[f]["__construct"] !== "undefined") {
|
||||
params = exports.phpFileFunctions[f]["__construct"].params;
|
||||
}
|
||||
params.forEach(function(value, key) {
|
||||
if (value) params[key] = "$" + value[1];
|
||||
});
|
||||
if (currentClass.startsWith("\\")) currentClass = currentClass.substr(1);
|
||||
var newSuggestion = new vscode.CompletionItem(currentClass, vscode.CompletionItemKind.Class);
|
||||
if (typeof clas[1] == "undefined" && typeof exports.phpFileUses[currentPath] !== "undefined" && typeof exports.phpFileUses[currentPath][currentClass] !== "undefined") {
|
||||
newSuggestion.insertText = currentClass.split("\\")[currentClass.split("\\").length - 1] + "(" + params.join(", ") + ");";
|
||||
} else {
|
||||
newSuggestion.insertText = "\\" + currentClass + "(" + params.join(", ") + ");";
|
||||
}
|
||||
newSuggestion.detail = "Class " + currentClass;
|
||||
suggestions.push(newSuggestion);
|
||||
} else if (use && (use[1] == currentWord || use[2] == "\\" + currentWord)) { // Use
|
||||
var currentClass = f.substr(0, f.length - 4);
|
||||
currentClass = currentClass.replace(new RegExp("\/", "g"), "\\");
|
||||
if (currentClass.startsWith("\\")) currentClass = currentClass.substr(1);
|
||||
var newSuggestion = new vscode.CompletionItem(currentClass, vscode.CompletionItemKind.Class);
|
||||
newSuggestion.detail = "Class " + currentClass;
|
||||
newSuggestion.insertText = currentClass + ";\n";
|
||||
suggestions.push(newSuggestion);
|
||||
} else if (!(execute && execute[1] == currentWord) && !(executeStatic && executeStatic[1] == currentWord)) { // static classes
|
||||
var currentClass = f.substr(0, f.length - 4);
|
||||
currentClass = currentClass.replace(new RegExp("\/", "g"), "\\");
|
||||
if (currentClass.startsWith("\\")) currentClass = currentClass.substr(1);
|
||||
var newSuggestion = new vscode.CompletionItem(currentClass, vscode.CompletionItemKind.Class);
|
||||
newSuggestion.detail = "Class " + currentClass;
|
||||
if (typeof exports.phpFileUses[currentPath] !== "undefined" && typeof exports.phpFileUses[currentPath][currentClass] !== "undefined") {
|
||||
newSuggestion.insertText = currentClass.split("\\")[currentClass.split("\\").length - 1] + "::";
|
||||
} else {
|
||||
newSuggestion.insertText = "\\" + currentClass + "::";
|
||||
}
|
||||
suggestions.push(newSuggestion);
|
||||
}
|
||||
}
|
||||
};
|
||||
return suggestions;
|
||||
}
|
||||
}));
|
||||
// Setup our plugin to help with function signatures
|
||||
context.subscriptions.push(vscode.languages.registerSignatureHelpProvider(phpMode_1.PHP_MODE, new phpFunctionSuggestions_1.PhpSignatureHelpProvider(vscode.workspace.getConfiguration('php')['docsTool']), '(', ','));
|
||||
// The command has been defined in the package.json file
|
||||
// Now provide the implementation of the command with registerCommand
|
||||
// The commandId parameter must match the command field in package.json
|
||||
var indexDisposable = vscode.commands.registerCommand('pmide.indexPhpFiles', () => {
|
||||
// The code you place here will be executed every time your command is executed
|
||||
indexPhpFiles();
|
||||
});
|
||||
var printDisposable = vscode.commands.registerCommand('pmide.printPhpFiles', () => {
|
||||
console.log(Object.keys(exports.phpFileFunctions).length);
|
||||
console.log(exports.phpFileUses);
|
||||
});
|
||||
context.subscriptions.push(indexDisposable);
|
||||
context.subscriptions.push(printDisposable);
|
||||
}
|
||||
exports.activate = activate;
|
||||
// this method is called when your extension is deactivated
|
||||
function deactivate() {}
|
||||
exports.deactivate = deactivate;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Function to handle the indexing of PHP files
|
||||
function indexPhpFiles() {
|
||||
// Clear out the cached data
|
||||
exports.phpFileUses = {};
|
||||
exports.phpFileFunctions = {};
|
||||
var indexResult = vscode.workspace.findFiles("**/*.php", "", 1000).then(function(list) {
|
||||
if (list) {
|
||||
var p = new Promise(function(resolve, reject) {
|
||||
list.forEach((phpFile) => {
|
||||
var path = phpFile.fsPath;
|
||||
var fileName = path.replace(vscode.workspace.rootPath, "").replace("src/", "").slice(1);
|
||||
if (!(fileName in exports.phpFileFunctions)) {
|
||||
exports.phpFileFunctions[fileName] = [];
|
||||
}
|
||||
if (!(fileName in exports.phpFileStaticFunctions)) {
|
||||
exports.phpFileStaticFunctions[fileName] = [];
|
||||
}
|
||||
// Read through the PHP file for includes/requires and function definitions
|
||||
var read = require('fs').readFileSync(path, 'utf8');
|
||||
var lineReader = read.split("\n");
|
||||
try {
|
||||
lineReader.forEach(function(line) {
|
||||
// Thats a bit messy for this one so: $2 = optionnal description comment, $4 = functions specifications (static, public, abstract, final,...), $7 = function name, $8 = arguments, $14 = return of function
|
||||
var functionRegex = /(\/\*\*?((\s|.|\n)+)\*\/)?\s*(((abstract|public|protected|private|final|static)\s*)*)function\s+(\w+)\(((\s*\w+)?\s*\$\w+\s*(,(\s*\w+)?\s*\$\w+\s*)*\s*)?\)\s*(:\s*(\w+)\s*)?({|;)/mig
|
||||
var match = functionRegex.exec(line);
|
||||
if (match) {
|
||||
// Matching function modifiers
|
||||
var functionModifiersLitteral = match[4].replace(/\s/, " ").split(" ");
|
||||
var functionModifiers = {
|
||||
"abstract": false,
|
||||
"public": false,
|
||||
"protected": false,
|
||||
"private": false,
|
||||
"final": false,
|
||||
"static": false
|
||||
};
|
||||
functionModifiersLitteral.forEach(function(modifier) {
|
||||
functionModifiers[modifier] = true;
|
||||
})
|
||||
var comment = typeof match[3] !== "undefined" ? match[3].replace(/[*]/gim, "") : "From " + fileName;
|
||||
// Parameters
|
||||
var params = [];
|
||||
if (typeof match[8] !== "undefined") match[8].replace(/\s*,\s*/, ",").split(",").forEach(function(m) {
|
||||
var paramers = /((\w+)\s+)?(\$\w+)(\s*\=[^,)]+)?/.exec(m)
|
||||
if (typeof paramers !== "undefined" && paramers !== null) params.push([paramers[0], paramers[3], paramers[2], paramers[5]]); // Later use of knowning which equals to what.
|
||||
});
|
||||
// Exporting function
|
||||
if (!functionModifiers.static) {
|
||||
exports.phpFileFunctions[fileName][match[7]] = {
|
||||
function: match[7],
|
||||
params: params,
|
||||
functionModifiers: functionModifiers,
|
||||
comment: comment
|
||||
};
|
||||
} else {
|
||||
exports.phpFileStaticFunctions[fileName][match[7]] = {
|
||||
function: match[7],
|
||||
params: params,
|
||||
functionModifiers: functionModifiers,
|
||||
comment: comment
|
||||
};
|
||||
}
|
||||
}
|
||||
// Check for uses
|
||||
var includeRegex = /use\s+((\w+\\)*)(\w+)(\s+as\s+(\w+)\s*)?;/;
|
||||
match = includeRegex.exec(line);
|
||||
if (match) {
|
||||
if (!(fileName in exports.phpFileUses)) {
|
||||
exports.phpFileUses[fileName] = [];
|
||||
}
|
||||
// Check if there is a match of "as" to set it.
|
||||
var classType = '';
|
||||
if (typeof match[4] !== "undefined") {
|
||||
classType = match[5];
|
||||
} else {
|
||||
classType = match[3];
|
||||
}
|
||||
exports.phpFileUses[fileName][match[1] + match[3]] = classType;
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
})
|
||||
} else {
|
||||
console.log("No workspace defined");
|
||||
}
|
||||
}, function(reason) {
|
||||
console.log("Error: " + reason);
|
||||
});
|
||||
|
||||
// Libraries
|
||||
if (require('fs').existsSync(vscode.workspace.getConfiguration('php')['pocketMinePath'])) {
|
||||
var libraryResult = require("child_process").execSync("find " + vscode.workspace.getConfiguration('php')['pocketMinePath'] + " -maxdepth 10 -type f | fgrep .php").toString().split("\n");
|
||||
if (libraryResult) {
|
||||
libraryResult.forEach(function(path) {
|
||||
if (require('fs').existsSync(path)) {
|
||||
var fileName = path.replace(vscode.workspace.getConfiguration('php')['pocketMinePath'], "").slice(1);
|
||||
if (!(fileName in exports.phpFileFunctions)) {
|
||||
exports.phpFileFunctions[fileName] = {};
|
||||
}
|
||||
if (!(fileName in exports.phpFileStaticFunctions)) {
|
||||
exports.phpFileStaticFunctions[fileName] = [];
|
||||
}
|
||||
// Read through the PHP file for includes/requires and function definitions
|
||||
var read = require('fs').readFileSync(path, 'utf8');
|
||||
try {
|
||||
var lineReader = read.split("\n");
|
||||
lineReader.forEach(function(line) {
|
||||
// Thats a bit messy for this one so: $2 = optionnal description comment, $4 = functions specifications (static, public, abstract, final,...), $7 = function name, $8 = arguments, $14 = return of function
|
||||
var functionRegex = /(\/\*\*?((\s|.|\n)+)\*\/)?\s*(((abstract|public|protected|private|final|static)\s*)*)function\s+(\w+)\(((\s*\w+)?\s*\$\w+\s*(,(\s*\w+)?\s*\$\w+\s*)*\s*)?\)\s*(:\s*(\w+)\s*)?({|;)/mig
|
||||
var match = functionRegex.exec(line);
|
||||
if (match) {
|
||||
// Matching function modifiers
|
||||
var functionModifiersLitteral = match[4].replace(/\s/, " ").split(" ");
|
||||
var functionModifiers = {
|
||||
"abstract": false,
|
||||
"public": false,
|
||||
"protected": false,
|
||||
"private": false,
|
||||
"final": false,
|
||||
"static": false
|
||||
};
|
||||
functionModifiersLitteral.forEach(function(modifier) {
|
||||
functionModifiers[modifier] = true;
|
||||
})
|
||||
var comment = typeof match[3] !== "undefined" ? match[3].replace(/[*]/gim, "") : "From " + fileName;
|
||||
// Parameters
|
||||
var params = [];
|
||||
if (typeof match[8] !== "undefined") match[8].replace(/\s*,\s*/, ",").split(",").forEach(function(m) {
|
||||
var paramers = /((\w+)\s+)?(\$\w+)(\s*\=[^,)]+)?/.exec(m)
|
||||
if (typeof paramers !== "undefined" && paramers !== null) params.push([paramers[0], paramers[3], paramers[2], paramers[5]]); // Later use of knowning which equals to what.
|
||||
});
|
||||
// Exporting function
|
||||
if (!functionModifiers.static) {
|
||||
exports.phpFileFunctions[fileName][match[7]] = {
|
||||
function: match[7],
|
||||
params: params,
|
||||
functionModifiers: functionModifiers,
|
||||
comment: comment
|
||||
};
|
||||
} else {
|
||||
exports.phpFileStaticFunctions[fileName][match[7]] = {
|
||||
function: match[7],
|
||||
params: params,
|
||||
functionModifiers: functionModifiers,
|
||||
comment: comment
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err); // Fails silently later
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log("No workspace defined");
|
||||
}
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=extension.js.map
|
153
out/src/phpDeclaration.js
Normal file
153
out/src/phpDeclaration.js
Normal file
|
@ -0,0 +1,153 @@
|
|||
/*---------------------------------------------------------
|
||||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------*/
|
||||
'use strict';
|
||||
const vscode = require('vscode');
|
||||
const cp = require('child_process');
|
||||
const path = require('path');
|
||||
function definitionLocation(document, position, toolForDocs, includeDocs = true) {
|
||||
return getGoVersion().then((ver) => {
|
||||
if (!ver) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
if (toolForDocs === 'godoc' || ver.major < 1 || (ver.major === 1 && ver.minor < 6)) {
|
||||
return definitionLocation_godef(document, position, includeDocs);
|
||||
}
|
||||
return definitionLocation_gogetdoc(document, position);
|
||||
});
|
||||
}
|
||||
exports.definitionLocation = definitionLocation;
|
||||
function definitionLocation_godef(document, position, includeDocs = true) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let wordAtPosition = document.getWordRangeAtPosition(position);
|
||||
let offset = byteOffsetAt(document, position);
|
||||
let godef = getBinPath('godef');
|
||||
// Spawn `godef` process
|
||||
let p = cp.execFile(godef, ['-t', '-i', '-f', document.fileName, '-o', offset.toString()], {}, (err, stdout, stderr) => {
|
||||
try {
|
||||
if (err && err.code === 'ENOENT') {
|
||||
promptForMissingTool('godef');
|
||||
}
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return resolve(null);
|
||||
}
|
||||
;
|
||||
let result = stdout.toString();
|
||||
let lines = result.split('\n');
|
||||
let match = /(.*):(\d+):(\d+)/.exec(lines[0]);
|
||||
if (!match) {
|
||||
// TODO: Gotodef on pkg name:
|
||||
// /usr/local/go/src/html/template\n
|
||||
return resolve(null);
|
||||
}
|
||||
let [_, file, line, col] = match;
|
||||
let signature = lines[1];
|
||||
let godoc = getBinPath('godoc');
|
||||
let pkgPath = path.dirname(file);
|
||||
let definitionInformation = {
|
||||
file: file,
|
||||
line: +line - 1,
|
||||
column: +col - 1,
|
||||
declarationlines: lines.splice(1),
|
||||
toolUsed: 'godef',
|
||||
doc: null,
|
||||
name: null
|
||||
};
|
||||
if (!includeDocs) {
|
||||
return resolve(definitionInformation);
|
||||
}
|
||||
cp.execFile(godoc, [pkgPath], {}, (err, stdout, stderr) => {
|
||||
if (err && err.code === 'ENOENT') {
|
||||
vscode.window.showInformationMessage('The "godoc" command is not available.');
|
||||
}
|
||||
let godocLines = stdout.toString().split('\n');
|
||||
let doc = '';
|
||||
let sigName = signature.substring(0, signature.indexOf(' '));
|
||||
let sigParams = signature.substring(signature.indexOf(' func') + 5);
|
||||
let searchSignature = 'func ' + sigName + sigParams;
|
||||
for (let i = 0; i < godocLines.length; i++) {
|
||||
if (godocLines[i] === searchSignature) {
|
||||
while (godocLines[++i].startsWith(' ')) {
|
||||
doc += godocLines[i].substring(4) + '\n';
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (doc !== '') {
|
||||
definitionInformation.doc = doc;
|
||||
}
|
||||
return resolve(definitionInformation);
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
p.stdin.end(document.getText());
|
||||
});
|
||||
}
|
||||
function definitionLocation_gogetdoc(document, position) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let wordAtPosition = document.getWordRangeAtPosition(position);
|
||||
let offset = byteOffsetAt(document, position);
|
||||
let gogetdoc = getBinPath('gogetdoc');
|
||||
let p = cp.execFile(gogetdoc, ['-u', '-json', '-modified', '-pos', document.fileName + ':#' + offset.toString()], {}, (err, stdout, stderr) => {
|
||||
try {
|
||||
if (err && err.code === 'ENOENT') {
|
||||
promptForMissingTool('gogetdoc');
|
||||
}
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return resolve(null);
|
||||
}
|
||||
;
|
||||
let goGetDocOutput = JSON.parse(stdout.toString());
|
||||
let match = /(.*):(\d+):(\d+)/.exec(goGetDocOutput.pos);
|
||||
let definitionInfo = {
|
||||
file: null,
|
||||
line: 0,
|
||||
column: 0,
|
||||
toolUsed: 'gogetdoc',
|
||||
declarationlines: goGetDocOutput.decl.split('\n'),
|
||||
doc: goGetDocOutput.doc,
|
||||
name: goGetDocOutput.name
|
||||
};
|
||||
if (!match) {
|
||||
return resolve(definitionInfo);
|
||||
}
|
||||
let [_, file, line, col] = match;
|
||||
definitionInfo.file = match[1];
|
||||
definitionInfo.line = +match[2] - 1;
|
||||
definitionInfo.column = +match[3] - 1;
|
||||
return resolve(definitionInfo);
|
||||
}
|
||||
catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
let documentText = document.getText();
|
||||
let documentArchive = document.fileName + '\n';
|
||||
documentArchive = documentArchive + Buffer.byteLength(documentText) + '\n';
|
||||
documentArchive = documentArchive + documentText;
|
||||
p.stdin.end(documentArchive);
|
||||
});
|
||||
}
|
||||
class GoDefinitionProvider {
|
||||
constructor(toolForDocs) {
|
||||
this.toolForDocs = 'godoc';
|
||||
this.toolForDocs = toolForDocs;
|
||||
}
|
||||
provideDefinition(document, position, token) {
|
||||
return definitionLocation(document, position, this.toolForDocs, false).then(definitionInfo => {
|
||||
if (definitionInfo == null || definitionInfo.file == null)
|
||||
return null;
|
||||
let definitionResource = vscode.Uri.file(definitionInfo.file);
|
||||
let pos = new vscode.Position(definitionInfo.line, definitionInfo.column);
|
||||
return new vscode.Location(definitionResource, pos);
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.GoDefinitionProvider = GoDefinitionProvider;
|
||||
//# sourceMappingURL=phpDeclaration.js.map
|
91
out/src/phpFunctionSuggestions.js
Normal file
91
out/src/phpFunctionSuggestions.js
Normal file
|
@ -0,0 +1,91 @@
|
|||
'use strict';
|
||||
const vscode = require('vscode');
|
||||
const vscode_1 = require('vscode');
|
||||
// import { definitionLocation } from './phpDeclaration';
|
||||
// import { parameters } from './util';
|
||||
const extension_1 = require('./extension');
|
||||
class PhpSignatureHelpProvider {
|
||||
constructor(toolForDocs) {
|
||||
this.toolForDocs = 'phpdoc';
|
||||
this.toolForDocs = toolForDocs;
|
||||
}
|
||||
provideSignatureHelp(document, position, token) {
|
||||
let theCall = this.walkBackwardsToBeginningOfCall(document, position);
|
||||
if (theCall == null) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
// Find the name of the function that's being called
|
||||
let functionNameRange = this.previousTokenPosition(document, theCall.openParen);
|
||||
let functionName = document.getText(functionNameRange);
|
||||
let result = new vscode_1.SignatureHelp();
|
||||
let declarationText, sig;
|
||||
let si;
|
||||
let currentFileName = document.uri.fsPath.replace(vscode.workspace.rootPath, '').slice(1).replace('\\', '/');
|
||||
if (currentFileName in extension_1.phpFileIncludes) {
|
||||
extension_1.phpFileIncludes[currentFileName].forEach(function (file) {
|
||||
if (file in extension_1.phpFileFunctions) {
|
||||
// Look through all the functions declared in the included/required file
|
||||
extension_1.phpFileFunctions[file].forEach(function (func) {
|
||||
// If the included/required function starts with the letter of our current word then add it to the set of suggestions
|
||||
if (func.function == functionName) {
|
||||
si = new vscode_1.SignatureInformation(func.function);
|
||||
si.parameters = [];
|
||||
func.params.forEach(function (param) {
|
||||
si.parameters.push(param);
|
||||
});
|
||||
// Set the documentation of the SignatureInformation to be the full function signature
|
||||
si.documentation = file + " : " + func.function + "(" + si.parameters.join(',') + ')';
|
||||
result.signatures = [si];
|
||||
result.activeSignature = 0;
|
||||
result.activeParameter = Math.min(theCall.commas.length, si.parameters.length - 1);
|
||||
result.signatures[0].label = functionName + ": " + result.signatures[0].parameters[result.activeParameter];
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// console.log("Result: ", result);
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
else {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
}
|
||||
previousTokenPosition(document, position) {
|
||||
while (position.character > 0) {
|
||||
let word = document.getWordRangeAtPosition(position);
|
||||
if (word) {
|
||||
return word;
|
||||
}
|
||||
position = position.translate(0, -1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
walkBackwardsToBeginningOfCall(document, position) {
|
||||
let currentLine = document.lineAt(position.line).text.substring(0, position.character);
|
||||
let parenBalance = 0;
|
||||
let commas = [];
|
||||
for (let char = position.character; char >= 0; char--) {
|
||||
switch (currentLine[char]) {
|
||||
case '(':
|
||||
parenBalance--;
|
||||
if (parenBalance < 0) {
|
||||
return {
|
||||
openParen: new vscode_1.Position(position.line, char),
|
||||
commas: commas
|
||||
};
|
||||
}
|
||||
break;
|
||||
case ')':
|
||||
parenBalance++;
|
||||
break;
|
||||
case ',':
|
||||
if (parenBalance === 0) {
|
||||
commas.push(new vscode_1.Position(position.line, char));
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
exports.PhpSignatureHelpProvider = PhpSignatureHelpProvider;
|
||||
//# sourceMappingURL=phpFunctionSuggestions.js.map
|
70
package.json
Normal file
70
package.json
Normal file
|
@ -0,0 +1,70 @@
|
|||
{
|
||||
"name": "pocketmine-ide",
|
||||
"displayName": "PocketMine IDE",
|
||||
"description": "Implementation of external PocketMine/PHP libs",
|
||||
"version": "0.0.1",
|
||||
"publisher": "Ad5001",
|
||||
"homepage": "https://github.com/Ad5001/PocketMine-IDE",
|
||||
"keywords": [
|
||||
"PocketMine",
|
||||
"IDE",
|
||||
"PHP",
|
||||
"Lib"
|
||||
],
|
||||
"icon": "icon.png",
|
||||
"author": {
|
||||
"name": "Ad5001",
|
||||
"email": "mail@ad5001.eu",
|
||||
"url": "https://en.ad5001.eu"
|
||||
},
|
||||
"license": "https://raw.githubusercontent.com/BoxOfDevs/Functions/master/LICENSE",
|
||||
"engines": {
|
||||
"vscode": "^1.5.0"
|
||||
},
|
||||
"categories": [
|
||||
"Other"
|
||||
],
|
||||
"activationEvents": [
|
||||
"onCommand:pmide.indexPhpFiles",
|
||||
"onCommand:pmide.printPhpFiles",
|
||||
"onLanguage:php"
|
||||
],
|
||||
"main": "./out/src/extension",
|
||||
"contributes": {
|
||||
"commands": [{
|
||||
"command": "pmide.indexPhpFiles",
|
||||
"title": "PocketMine IDE - Index PHP Files"
|
||||
},
|
||||
{
|
||||
"command": "pmide.printPhpFiles",
|
||||
"title": "PocketMine IDE - Print PHP Files"
|
||||
}
|
||||
],
|
||||
"configuration": {
|
||||
"properties": {
|
||||
"php.pocketMinePath": {
|
||||
"type": "string",
|
||||
"default": null,
|
||||
"description": "The pocketmine/library you want to use path"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "tsc -p ./",
|
||||
"compile": "tsc -watch -p ./",
|
||||
"postinstall": "node ./node_modules/vscode/bin/install"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^2.0.3",
|
||||
"vscode": "^1.0.0",
|
||||
"mocha": "^2.3.3",
|
||||
"@types/node": "^6.0.40",
|
||||
"@types/mocha": "^2.2.32"
|
||||
},
|
||||
"__metadata": {
|
||||
"id": "f6b4e2a7-5b92-41a1-870a-78abef140e5c",
|
||||
"publisherId": "96452d5f-7333-47a6-9960-9cf179d6f173",
|
||||
"publisherDisplayName": "Ad5001"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue