0.0.5 - Fixing some bugs

This commit is contained in:
Adsooi 2017-11-15 23:06:45 +01:00
parent a377575a05
commit 17ac671153
9 changed files with 138 additions and 298 deletions

0
.vscode/launch.json vendored Normal file → Executable file
View file

0
.vsixmanifest Normal file → Executable file
View file

0
README.md Normal file → Executable file
View file

0
icon.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

0
icon.xcf Normal file → Executable file
View file

14
out/src/extension.js Normal file → Executable file
View file

@ -19,9 +19,9 @@ exports.currentPath = "";
function activate(context) { function activate(context) {
// Do the initial indexing // Do the initial indexing
Indexer.indexPhpFiles(); Indexer.indexPhpFiles();
// require("fs").appendFileSync("/home/ad5001/echo.txt", JSON.stringify(Indexer.phpFileProperties)) // require("fs").appendFileSync("/home/ad5001/echo.txt", JSON.stringify(Indexer.phpFileProperties))
vscode.workspace.onDidSaveTextDocument(function (document) { vscode.workspace.onDidSaveTextDocument(function(document) {
Indexer.indexPhpFiles(); Indexer.indexPhpFiles();
}); });
@ -79,7 +79,7 @@ function activate(context) {
} }
} }
}; };
Indexer.done = {};// Reseting cache Indexer.done = {}; // Reseting cache
return suggestions; return suggestions;
} }
})); }));
@ -91,15 +91,15 @@ function activate(context) {
/** /**
* Reindex php files command * Reindex php files command
*/ */
var indexDisposable = vscode.commands.registerCommand('pmide.indexPhpFiles', function () { var indexDisposable = vscode.commands.registerCommand('pmide.indexPhpFiles', function() {
Indexer.indexPhpFiles(); Indexer.indexPhpFiles();
}); });
/** /**
* Prints everything about PHP files. * Prints everything about PHP files.
*/ */
var printDisposable = vscode.commands.registerCommand('pmide.printPhpFiles', function () { var printDisposable = vscode.commands.registerCommand('pmide.printPhpFiles', function() {
console.log(Object.keys(Indexer.phpFileFunctions).length); console.log(Object.keys(Indexer.phpFileFunctions).length);
console.log(Indexer.phpFileUses); console.log(Indexer.phpFileUses, Indexer.phpFileFunctions);
}); });
context.subscriptions.push(indexDisposable); context.subscriptions.push(indexDisposable);
context.subscriptions.push(printDisposable); context.subscriptions.push(printDisposable);
@ -107,4 +107,4 @@ function activate(context) {
exports.activate = activate; exports.activate = activate;
exports.deactivate = function () { }; exports.deactivate = function() {};

139
out/src/phpCompletionItem.js Normal file → Executable file
View file

@ -19,7 +19,7 @@ exports.Indexer = {
phpFileProperties: {}, phpFileProperties: {},
/** @var {Object} */ /** @var {Object} */
done: {}, done: {},
/** /**
@ -35,18 +35,18 @@ exports.Indexer = {
for (var func in exports.Indexer.phpFileFunctions[file]) { for (var func in exports.Indexer.phpFileFunctions[file]) {
func = exports.Indexer.phpFileFunctions[file][func]; func = exports.Indexer.phpFileFunctions[file][func];
if (func.function.startsWith(currentWord) && execute[1] == currentWord && (func.functionModifiers["public"] || file == ext.currentPath)) { if (func.function.startsWith(currentWord) && execute[1] == currentWord && (func.functionModifiers["public"] || file == ext.currentPath)) {
if(typeof exports.Indexer.done[func.function] == "undefined" /*|| exports.Indexer.done[func.function].params !== func.params */) { // Preventing from spamming same method over and over if (typeof exports.Indexer.done[func.function] == "undefined" /*|| exports.Indexer.done[func.function].params !== func.params */ ) { // Preventing from spamming same method over and over
var newSuggestion = new vscode.CompletionItem(func.function, vscode.CompletionItemKind.Function); var newSuggestion = new vscode.CompletionItem(func.function, vscode.CompletionItemKind.Function);
params = func.params; params = func.params;
var parameters = []; var parameters = [];
params.forEach(function (value, key) { params.forEach(function(value, key) {
if (value) { if (value) {
params[key] = "$" + value[1]; params[key] = "$" + value[1];
parameters[key] = (typeof value[2] !== "undefined" ? value[2] + " " : "") + value[1]; parameters[key] = (typeof value[2] !== "undefined" ? value[2] + " " : "") + value[1];
parameters[key] += typeof value[3] !== "undefined" ? " = " + value[3] : ""; parameters[key] += typeof value[3] !== "undefined" ? " = " + value[3] : "";
} }
}); });
newSuggestion.insertText = func.function + "(" + params.join(", ") + ")"; newSuggestion.insertText = func.function+"(" + params.join(", ") + ")";
newSuggestion.documentation = func.comment; newSuggestion.documentation = func.comment;
newSuggestion.detail = "(function) (" + parameters.join(", ") + ")"; newSuggestion.detail = "(function) (" + parameters.join(", ") + ")";
suggestions.push(newSuggestion); suggestions.push(newSuggestion);
@ -67,22 +67,22 @@ exports.Indexer = {
* @return {vscode.CompletionItem[]} * @return {vscode.CompletionItem[]}
*/ */
getStaticFunctionsFromFile(file, suggestions, currentWord, executeStatic) { getStaticFunctionsFromFile(file, suggestions, currentWord, executeStatic) {
for (var func in exports.Indexer.phpFileStaticFunctions[file]) { for (var func in exports.Indexer.phpFileStaticFunctions[file]) {
func = exports.Indexer.phpFileStaticFunctions[file][func]; func = exports.Indexer.phpFileStaticFunctions[file][func];
if (func.function.startsWith(currentWord) && executeStatic[1] == currentWord) { if (func.function.startsWith(currentWord) && executeStatic[1] == currentWord) {
if(typeof exports.Indexer.done[func.function] == "undefined" /*|| exports.Indexer.done[func.function].params !== func.params*/) { // Preventing from spamming same method over and over if (typeof exports.Indexer.done[func.function] == "undefined" /*|| exports.Indexer.done[func.function].params !== func.params*/ ) { // Preventing from spamming same method over and over
var newSuggestion = new vscode.CompletionItem(func.function, vscode.CompletionItemKind.Function); var newSuggestion = new vscode.CompletionItem(func.function, vscode.CompletionItemKind.Function);
var params = func.params; var params = func.params;
var parameters = []; var parameters = [];
params.forEach(function (value, key) { params.forEach(function(value, key) {
if (value) { if (value) {
params[key] = "$" + value[1]; params[key] = "$" + value[1];
parameters[key] = (typeof value[2] !== "undefined" ? value[2] + " " : "") + value[1]; parameters[key] = (typeof value[2] !== "undefined" ? value[2] + " " : "") + value[1];
parameters[key] += typeof value[3] !== "undefined" ? " = " + value[3] : ""; parameters[key] += typeof value[3] !== "undefined" ? " = " + value[3] : "";
} }
}) })
newSuggestion.insertText = func.function + "(" + params.join(", ") + ")"; newSuggestion.insertText = func.function+"(" + params.join(", ") + ")";
newSuggestion.documentation = func.comment; newSuggestion.documentation = func.comment;
newSuggestion.detail = "(function) (" + parameters.join(", ") + ")"; newSuggestion.detail = "(function) (" + parameters.join(", ") + ")";
suggestions.push(newSuggestion); suggestions.push(newSuggestion);
@ -104,11 +104,11 @@ exports.Indexer = {
* @return {vscode.CompletionItem[]} * @return {vscode.CompletionItem[]}
*/ */
getPropertiesFromFile(file, suggestions, currentWord, execute) { getPropertiesFromFile(file, suggestions, currentWord, execute) {
for (var func in exports.Indexer.phpFileProperties[file]) { for (var func in exports.Indexer.phpFileProperties[file]) {
func = exports.Indexer.phpFileProperties[file][func]; func = exports.Indexer.phpFileProperties[file][func];
if (func[0].startsWith(currentWord) && execute[1] == currentWord && func[1] == PROPERTY_NORMAL) { if (func[0].startsWith(currentWord) && execute[1] == currentWord && func[1] == PROPERTY_NORMAL) {
if(typeof exports.Indexer.done[func[0]] == "undefined") { // Preventing from spamming same method over and over if (typeof exports.Indexer.done[func[0]] == "undefined") { // Preventing from spamming same method over and over
var newSuggestion = new vscode.CompletionItem(func[0], vscode.CompletionItemKind.Property); var newSuggestion = new vscode.CompletionItem(func[0], vscode.CompletionItemKind.Property);
newSuggestion.insertText = func[0]; newSuggestion.insertText = func[0];
newSuggestion.detail = "(property) " + file.substr(0, file.length - 4).replace(new RegExp("\/", "g"), "\\"); newSuggestion.detail = "(property) " + file.substr(0, file.length - 4).replace(new RegExp("\/", "g"), "\\");
@ -130,23 +130,23 @@ exports.Indexer = {
* @return {vscode.CompletionItem[]} * @return {vscode.CompletionItem[]}
*/ */
getStaticPropertiesFromFile(file, suggestions, currentWord, executeStatic) { getStaticPropertiesFromFile(file, suggestions, currentWord, executeStatic) {
for (var func in exports.Indexer.phpFileProperties[file]) { for (var func in exports.Indexer.phpFileProperties[file]) {
func = exports.Indexer.phpFileProperties[file][func]; func = exports.Indexer.phpFileProperties[file][func];
if (func[0].startsWith(currentWord) && executeStatic[1] == currentWord) { if (func[0].startsWith(currentWord) && executeStatic[1] == currentWord) {
if(typeof exports.Indexer.done[func[0]] == "undefined") { // Preventing from spamming same method over and over if (typeof exports.Indexer.done[func[0]] == "undefined") { // Preventing from spamming same method over and over
if(func[1] == PROPERTY_STATIC){ if (func[1] == PROPERTY_STATIC) {
var newSuggestion = new vscode.CompletionItem("$" + func[0], vscode.CompletionItemKind.Property); var newSuggestion = new vscode.CompletionItem("$" + func[0], vscode.CompletionItemKind.Property);
newSuggestion.insertText = "$" + func[0]; newSuggestion.insertText = "$" + func[0];
newSuggestion.detail = "(property) " + file.substr(0, file.length - 4).replace(new RegExp("\/", "g"), "\\"); newSuggestion.detail = "(property) " + file.substr(0, file.length - 4).replace(new RegExp("\/", "g"), "\\");
exports.Indexer.done[func[0]] = true; exports.Indexer.done[func[0]] = true;
} else if(func[1] == PROPERTY_CONST){ } else if (func[1] == PROPERTY_CONST) {
var newSuggestion = new vscode.CompletionItem(func[0], vscode.CompletionItemKind.Constant); var newSuggestion = new vscode.CompletionItem(func[0], vscode.CompletionItemKind.Constant);
newSuggestion.insertText = func[0]; newSuggestion.insertText = func[0];
newSuggestion.detail = "(constant) " + file.substr(0, file.length - 4).replace(new RegExp("\/", "g"), "\\"); newSuggestion.detail = "(constant) " + file.substr(0, file.length - 4).replace(new RegExp("\/", "g"), "\\");
exports.Indexer.done[func[0]] = true; exports.Indexer.done[func[0]] = true;
} }
if(newSuggestion) suggestions.push(newSuggestion); if (newSuggestion) suggestions.push(newSuggestion);
} }
} }
}; };
@ -187,13 +187,13 @@ exports.Indexer = {
if (typeof exports.Indexer.phpFileFunctions[file]["__construct"] !== "undefined") { if (typeof exports.Indexer.phpFileFunctions[file]["__construct"] !== "undefined") {
params = exports.Indexer.phpFileFunctions[file]["__construct"].params; params = exports.Indexer.phpFileFunctions[file]["__construct"].params;
} }
params.forEach(function (value, key) { params.forEach(function(value, key) {
if (value) params[key] = "$" + value[2]; if (value) params[key] = "$" + value[2];
}); });
if (currentClass.startsWith("\\")) currentClass = currentClass.substr(1); if (currentClass.startsWith("\\")) currentClass = currentClass.substr(1);
var newSuggestion = new vscode.CompletionItem(currentClass, vscode.CompletionItemKind.Class); var newSuggestion = new vscode.CompletionItem(currentClass, vscode.CompletionItemKind.Class);
if (typeof clas[1] == "undefined" && if (typeof clas[1] == "undefined" &&
typeof exports.Indexer.phpFileUses[currentPath] !== "undefined" && typeof exports.Indexer.phpFileUses[currentPath] !== "undefined" &&
typeof exports.Indexer.phpFileUses[currentPath][currentClass] !== "undefined") { typeof exports.Indexer.phpFileUses[currentPath][currentClass] !== "undefined") {
newSuggestion.insertText = currentClass.split("\\")[currentClass.split("\\").length - 1] + "(" + params.join(", ") + ");"; newSuggestion.insertText = currentClass.split("\\")[currentClass.split("\\").length - 1] + "(" + params.join(", ") + ");";
} else { } else {
@ -218,12 +218,13 @@ exports.Indexer = {
getClassNormal(file, suggestions, currentPath) { getClassNormal(file, suggestions, currentPath) {
var currentClass = file.substr(0, file.length - 4).replace(new RegExp("\/", "g"), "\\"); var currentClass = file.substr(0, file.length - 4).replace(new RegExp("\/", "g"), "\\");
var currentPath2 = currentPath.substr(1); var currentPath2 = currentPath.substr(1);
currentClass = currentClass.replace(new RegExp("\/", "g"), "\\"); // currentClass = currentClass.replace(new RegExp("\/", "g"), "\\");
if (currentClass.startsWith("\\")) currentClass = currentClass.substr(1); if (currentClass.startsWith("\\")) currentClass = currentClass.substr(1);
var newSuggestion = new vscode.CompletionItem(currentClass, vscode.CompletionItemKind.Class); var newSuggestion = new vscode.CompletionItem(currentClass, vscode.CompletionItemKind.Class);
newSuggestion.detail = "(class) " + currentClass; newSuggestion.detail = "(class) " + currentClass;
if (typeof exports.Indexer.phpFileUses[currentPath] !== "undefined" && console.log(currentClass, exports.Indexer.phpFileUses[currentPath], exports.Indexer.phpFileUses[currentPath][currentClass]);
typeof exports.Indexer.phpFileUses[currentPath][currentClass] !== "undefined") { if (typeof exports.Indexer.phpFileUses[currentPath] !== "undefined" &&
typeof exports.Indexer.phpFileUses[currentPath][currentClass] !== "undefined") {
newSuggestion.insertText = currentClass.split("\\")[currentClass.split("\\").length - 1]; newSuggestion.insertText = currentClass.split("\\")[currentClass.split("\\").length - 1];
} else { } else {
newSuggestion.insertText = "\\" + currentClass; newSuggestion.insertText = "\\" + currentClass;
@ -253,41 +254,34 @@ exports.Indexer = {
var c = exports.Indexer.findFilesInDir(vscode.workspace.rootPath, ".php"); var c = exports.Indexer.findFilesInDir(vscode.workspace.rootPath, ".php");
libraryResult = libraryResult.concat(c); libraryResult = libraryResult.concat(c);
} }
libraryResult.forEach(function (path) { libraryResult.forEach(function(path) {
if (fs.existsSync(path)) { if (fs.existsSync(path)) {
var fileName = path.replace(vscode.workspace.rootPath, "").replace(vscode.workspace.getConfiguration('php')['pocketMinePath'], "").replace("src", "").slice(1); var fileName = path.replace(vscode.workspace.rootPath, "").replace(vscode.workspace.getConfiguration('php')['pocketMinePath'], "").replace("src", "").replace("//", "/");
if (typeof exports.Indexer.phpFileFunctions[fileName] == "undefined") { // Creating the default properties
exports.Indexer.phpFileFunctions[fileName] = {}; var fileProperties = ["phpFileFunctions", "phpFileStaticFunctions", "phpFileUses", "phpFileProperties"];
} fileProperties.forEach(function(func) {
if (typeof exports.Indexer.phpFileStaticFunctions[fileName] == "undefined") { if (typeof exports.Indexer[func][fileName] == "undefined") {
exports.Indexer.phpFileStaticFunctions[fileName] = {}; exports.Indexer[func][fileName] = {};
} }
if (typeof exports.Indexer.phpFileUses[fileName] == "undefined") { })
exports.Indexer.phpFileUses[fileName] = {}; // Read through the PHP file for includes/requires and function definitions
}
if (typeof exports.Indexer.phpFileProperties[fileName] == "undefined") {
exports.Indexer.phpFileProperties[fileName] = {};
}
// Read through the PHP file for includes/requires and function definitions
var read = fs.readFileSync(path, 'utf8'); var read = fs.readFileSync(path, 'utf8');
// Parsing class regexr // Parsing class regexr
var fileBaseName = (path.indexOf("/") ? path.split("/") : (path.indexOf("\\") ? path.split("\\") : [path])); var fileBaseName = (path.indexOf("/") ? path.split("/") : (path.indexOf("\\") ? path.split("\\") : [path]));
fileBaseName = fileBaseName[fileBaseName.length - 1].replace(/\.php$/, ""); fileBaseName = fileBaseName[fileBaseName.length - 1].replace(/\.php$/, "");
if(!read.match(new RegExp("(class|interface)\\s+" + fileBaseName, "mi"))) return; // if (!read.match(new RegExp("(class|interface)\\s+" + fileBaseName, "mi"))) return;
// var classRegexr = new RegExp("(class|interface)\\s+" + fileBaseName + "(\\s+extends ([\w_]+))?(\\s+implements ([\w_\\\\]+))?", "mi"); // var classRegexr = new RegExp("(class|interface)\\s+" + fileBaseName + "(\\s+extends ([\w_]+))?(\\s+implements ([\w_\\\\]+))?", "mi");
try {
var lineReader = read.split("\n"); var lineReader = read.split(/(\r|\n)/gim);
lineReader.forEach(function (line) { lineReader.forEach(function(line) {
// Parsing functions: // Parsing functions:
exports.Indexer.parseFunction(line, fileName); exports.Indexer.parseFunction(line, fileName);
// Parsing properties: // Parsing properties:
exports.Indexer.parseProperty(line, fileName); exports.Indexer.parseProperty(line, fileName);
// Check for uses // Check for uses
exports.Indexer.parseUse(line, fileName); exports.Indexer.parseUse(line, fileName);
}); });
} catch (err) {
console.error(err);
}
} }
}); });
}, },
@ -316,8 +310,7 @@ exports.Indexer = {
var stat = fs.lstatSync(filename); var stat = fs.lstatSync(filename);
if (stat.isDirectory()) { if (stat.isDirectory()) {
results = results.concat(exports.Indexer.findFilesInDir(filename, filter)); //recurse results = results.concat(exports.Indexer.findFilesInDir(filename, filter)); //recurse
} } else if (filename.indexOf(filter) >= 0) {
else if (filename.indexOf(filter) >= 0) {
results.push(filename); results.push(filename);
} }
} }
@ -325,11 +318,11 @@ exports.Indexer = {
}, },
/** /**
* Parses and exports.Indexer functions from a line. * Parses and exports.Indexer functions from a line.
* @param {String} line * @param {String} line
* @param {String} fileName * @param {String} fileName
*/ */
parseFunction(line, fileName) { parseFunction(line, fileName) {
// Thats a bit messy for exports.Indexer one so: $2 = optionnal description comment, $4 = functions specifications (static, public, abstract, final,...), $7 = function name, $8 = arguments, $14 = return of function // Thats a bit messy for exports.Indexer 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 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
@ -345,13 +338,13 @@ exports.Indexer = {
"final": false, "final": false,
"static": false "static": false
}; };
functionModifiersLitteral.forEach(function (modifier) { functionModifiersLitteral.forEach(function(modifier) {
functionModifiers[modifier] = true; functionModifiers[modifier] = true;
}) })
var comment = typeof match[3] !== "undefined" ? match[3].replace(/[*]/gim, "") : "From " + fileName; var comment = typeof match[3] !== "undefined" ? match[3].replace(/[*]/gim, "") : "From " + fileName;
// Parameters // Parameters
var params = []; var params = [];
if (typeof match[8] !== "undefined") match[8].replace(/\s*,\s*/, ",").split(",").forEach(function (m) { if (typeof match[8] !== "undefined") match[8].replace(/\s*,\s*/, ",").split(",").forEach(function(m) {
var paramers = /((\w+)\s+)?(\$\w+)(\s*\=[^,)]+)?/.exec(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. if (typeof paramers !== "undefined" && paramers !== null) params.push([paramers[0], paramers[3], paramers[2], paramers[5]]); // Later use of knowning which equals to what.
}); });
@ -375,14 +368,14 @@ exports.Indexer = {
}, },
/** /**
* Parses and exports.Indexer uses from a line. * Parses and exports.Indexer uses from a line.
* @param {String} line * @param {String} line
* @param {String} fileName * @param {String} fileName
*/ */
parseUse(line, fileName) { parseUse(line, fileName) {
var includeRegex = /use\s+((\w+\\)*)(\w+)(\s+as\s+(\w+)\s*)?;/; var includeRegex = /use\s+((\w+\\)*)(\w+)(\s+as\s+(\w+)\s*)?;/;
match = includeRegex.exec(line); var match = includeRegex.exec(line);
if (match) { if (match) {
// Check if there is a match of "as" to set it. // Check if there is a match of "as" to set it.
var classType = ''; var classType = '';
@ -396,18 +389,18 @@ exports.Indexer = {
}, },
/** /**
* Parses and exports Indexer properties (also static one) from a line. * Parses and exports Indexer properties (also static one) from a line.
* @param {String} line * @param {String} line
* @param {String} fileName * @param {String} fileName
*/ */
parseProperty(line, fileName) { parseProperty(line, fileName) {
var propertiesRegexr = /(protected|private|public|static|const)\s+(\$)?([\w_]+)\s*(;|=)/; var propertiesRegexr = /(protected|private|public|static|const)\s+(\$)?([\w_]+)\s*(;|=)/;
match = propertiesRegexr.exec(line); var match = propertiesRegexr.exec(line);
if (match) { if (match) {
if(match[1] == "static" && match[2] == "$") { if (match[1] == "static" && match[2] == "$") {
exports.Indexer.phpFileProperties[fileName][match[3]] = [match[3], PROPERTY_STATIC]; exports.Indexer.phpFileProperties[fileName][match[3]] = [match[3], PROPERTY_STATIC];
} else if(match[1] == "const") { } else if (match[1] == "const") {
exports.Indexer.phpFileProperties[fileName][match[3]] = [match[3], PROPERTY_CONST]; exports.Indexer.phpFileProperties[fileName][match[3]] = [match[3], PROPERTY_CONST];
} else { } else {
exports.Indexer.phpFileProperties[fileName][match[3]] = [match[3], PROPERTY_NORMAL]; exports.Indexer.phpFileProperties[fileName][match[3]] = [match[3], PROPERTY_NORMAL];

View file

@ -1,152 +0,0 @@
/*---------------------------------------------------------
* 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;

131
package.json Normal file → Executable file
View file

@ -1,68 +1,67 @@
{ {
"name": "pocketmine-ide", "name": "pocketmine-ide",
"displayName": "PocketMine IDE", "displayName": "PocketMine IDE",
"description": "Implementation of external PocketMine/PHP libs for Visual Studio Code", "description": "Implementation of external PocketMine/PHP libs for Visual Studio Code",
"version": "0.0.4", "version": "0.0.5",
"publisher": "Ad5001", "publisher": "Ad5001",
"homepage": "https://github.com/Ad5001/PocketMine-IDE", "homepage": "https://github.com/Ad5001/PocketMine-IDE",
"keywords": [ "keywords": [
"PocketMine", "PocketMine",
"IDE", "IDE",
"PHP", "PHP",
"Lib" "Lib"
], ],
"icon": "icon.png", "icon": "icon.png",
"author": { "author": {
"name": "Ad5001", "name": "Ad5001",
"email": "mail@ad5001.eu", "email": "mail@ad5001.eu",
"url": "https://en.ad5001.eu" "url": "https://en.ad5001.eu"
}, },
"license": "https://raw.githubusercontent.com/BoxOfDevs/Functions/master/LICENSE", "license": "https://raw.githubusercontent.com/BoxOfDevs/Functions/master/LICENSE",
"engines": { "engines": {
"vscode": "^1.5.0" "vscode": "^1.5.0"
}, },
"categories": [ "categories": [
"Other" "Other"
], ],
"activationEvents": [ "activationEvents": [
"onCommand:pmide.indexPhpFiles", "onCommand:pmide.indexPhpFiles",
"onCommand:pmide.printPhpFiles", "onCommand:pmide.printPhpFiles",
"onLanguage:php" "onLanguage:php"
], ],
"main": "./out/src/extension", "main": "./out/src/extension",
"contributes": { "contributes": {
"commands": [ "commands": [{
{ "command": "pmide.indexPhpFiles",
"command": "pmide.indexPhpFiles", "title": "PocketMine IDE - Index PHP Files"
"title": "PocketMine IDE - Index PHP Files" },
}, {
{ "command": "pmide.printPhpFiles",
"command": "pmide.printPhpFiles", "title": "PocketMine IDE - Print PHP Files"
"title": "PocketMine IDE - Print PHP Files" }
} ],
], "configuration": {
"configuration": { "properties": {
"properties": { "php.pocketMinePath": {
"php.pocketMinePath": { "type": "string",
"type": "string", "default": null,
"default": null, "description": "The pocketmine/library you want to use path"
"description": "The pocketmine/library you want to use path" }
} }
} }
} },
}, "scripts": {
"scripts": { "postinstall": "node ./node_modules/vscode/bin/install"
"postinstall": "node ./node_modules/vscode/bin/install" },
}, "devDependencies": {
"devDependencies": { "vscode": "^1.0.0",
"vscode": "^1.0.0", "mocha": "^2.3.3",
"mocha": "^2.3.3", "@types/node": "^6.0.40",
"@types/node": "^6.0.40", "@types/mocha": "^2.2.32"
"@types/mocha": "^2.2.32" },
}, "__metadata": {
"__metadata": { "id": "2282a6db-6533-4359-8697-10ccdd4a97de",
"id": "2282a6db-6533-4359-8697-10ccdd4a97de", "publisherId": "96452d5f-7333-47a6-9960-9cf179d6f173",
"publisherId": "96452d5f-7333-47a6-9960-9cf179d6f173", "publisherDisplayName": "Ad5001"
"publisherDisplayName": "Ad5001" }
}
} }