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

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

@ -21,7 +21,7 @@ function activate(context) {
Indexer.indexPhpFiles();
// require("fs").appendFileSync("/home/ad5001/echo.txt", JSON.stringify(Indexer.phpFileProperties))
vscode.workspace.onDidSaveTextDocument(function (document) {
vscode.workspace.onDidSaveTextDocument(function(document) {
Indexer.indexPhpFiles();
});
@ -79,7 +79,7 @@ function activate(context) {
}
}
};
Indexer.done = {};// Reseting cache
Indexer.done = {}; // Reseting cache
return suggestions;
}
}));
@ -91,15 +91,15 @@ function activate(context) {
/**
* Reindex php files command
*/
var indexDisposable = vscode.commands.registerCommand('pmide.indexPhpFiles', function () {
var indexDisposable = vscode.commands.registerCommand('pmide.indexPhpFiles', function() {
Indexer.indexPhpFiles();
});
/**
* 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(Indexer.phpFileUses);
console.log(Indexer.phpFileUses, Indexer.phpFileFunctions);
});
context.subscriptions.push(indexDisposable);
context.subscriptions.push(printDisposable);
@ -107,4 +107,4 @@ function activate(context) {
exports.activate = activate;
exports.deactivate = function () { };
exports.deactivate = function() {};

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

@ -35,18 +35,18 @@ exports.Indexer = {
for (var func in exports.Indexer.phpFileFunctions[file]) {
func = exports.Indexer.phpFileFunctions[file][func];
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);
params = func.params;
var parameters = [];
params.forEach(function (value, key) {
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.insertText = func.function+"(" + params.join(", ") + ")";
newSuggestion.documentation = func.comment;
newSuggestion.detail = "(function) (" + parameters.join(", ") + ")";
suggestions.push(newSuggestion);
@ -71,18 +71,18 @@ exports.Indexer = {
for (var func in exports.Indexer.phpFileStaticFunctions[file]) {
func = exports.Indexer.phpFileStaticFunctions[file][func];
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 params = func.params;
var parameters = [];
params.forEach(function (value, key) {
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.insertText = func.function+"(" + params.join(", ") + ")";
newSuggestion.documentation = func.comment;
newSuggestion.detail = "(function) (" + parameters.join(", ") + ")";
suggestions.push(newSuggestion);
@ -108,7 +108,7 @@ exports.Indexer = {
for (var func in exports.Indexer.phpFileProperties[file]) {
func = exports.Indexer.phpFileProperties[file][func];
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);
newSuggestion.insertText = func[0];
newSuggestion.detail = "(property) " + file.substr(0, file.length - 4).replace(new RegExp("\/", "g"), "\\");
@ -134,19 +134,19 @@ exports.Indexer = {
for (var func in exports.Indexer.phpFileProperties[file]) {
func = exports.Indexer.phpFileProperties[file][func];
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(func[1] == PROPERTY_STATIC){
if (typeof exports.Indexer.done[func[0]] == "undefined") { // Preventing from spamming same method over and over
if (func[1] == PROPERTY_STATIC) {
var newSuggestion = new vscode.CompletionItem("$" + func[0], vscode.CompletionItemKind.Property);
newSuggestion.insertText = "$" + func[0];
newSuggestion.detail = "(property) " + file.substr(0, file.length - 4).replace(new RegExp("\/", "g"), "\\");
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);
newSuggestion.insertText = func[0];
newSuggestion.detail = "(constant) " + file.substr(0, file.length - 4).replace(new RegExp("\/", "g"), "\\");
exports.Indexer.done[func[0]] = true;
}
if(newSuggestion) suggestions.push(newSuggestion);
if (newSuggestion) suggestions.push(newSuggestion);
}
}
};
@ -187,7 +187,7 @@ exports.Indexer = {
if (typeof exports.Indexer.phpFileFunctions[file]["__construct"] !== "undefined") {
params = exports.Indexer.phpFileFunctions[file]["__construct"].params;
}
params.forEach(function (value, key) {
params.forEach(function(value, key) {
if (value) params[key] = "$" + value[2];
});
if (currentClass.startsWith("\\")) currentClass = currentClass.substr(1);
@ -218,12 +218,13 @@ exports.Indexer = {
getClassNormal(file, suggestions, currentPath) {
var currentClass = file.substr(0, file.length - 4).replace(new RegExp("\/", "g"), "\\");
var currentPath2 = currentPath.substr(1);
currentClass = currentClass.replace(new RegExp("\/", "g"), "\\");
// 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;
console.log(currentClass, exports.Indexer.phpFileUses[currentPath], exports.Indexer.phpFileUses[currentPath][currentClass]);
if (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];
} else {
newSuggestion.insertText = "\\" + currentClass;
@ -253,41 +254,34 @@ exports.Indexer = {
var c = exports.Indexer.findFilesInDir(vscode.workspace.rootPath, ".php");
libraryResult = libraryResult.concat(c);
}
libraryResult.forEach(function (path) {
libraryResult.forEach(function(path) {
if (fs.existsSync(path)) {
var fileName = path.replace(vscode.workspace.rootPath, "").replace(vscode.workspace.getConfiguration('php')['pocketMinePath'], "").replace("src", "").slice(1);
if (typeof exports.Indexer.phpFileFunctions[fileName] == "undefined") {
exports.Indexer.phpFileFunctions[fileName] = {};
}
if (typeof exports.Indexer.phpFileStaticFunctions[fileName] == "undefined") {
exports.Indexer.phpFileStaticFunctions[fileName] = {};
}
if (typeof exports.Indexer.phpFileUses[fileName] == "undefined") {
exports.Indexer.phpFileUses[fileName] = {};
}
if (typeof exports.Indexer.phpFileProperties[fileName] == "undefined") {
exports.Indexer.phpFileProperties[fileName] = {};
}
// Read through the PHP file for includes/requires and function definitions
var fileName = path.replace(vscode.workspace.rootPath, "").replace(vscode.workspace.getConfiguration('php')['pocketMinePath'], "").replace("src", "").replace("//", "/");
// Creating the default properties
var fileProperties = ["phpFileFunctions", "phpFileStaticFunctions", "phpFileUses", "phpFileProperties"];
fileProperties.forEach(function(func) {
if (typeof exports.Indexer[func][fileName] == "undefined") {
exports.Indexer[func][fileName] = {};
}
})
// Read through the PHP file for includes/requires and function definitions
var read = fs.readFileSync(path, 'utf8');
// Parsing class regexr
var fileBaseName = (path.indexOf("/") ? path.split("/") : (path.indexOf("\\") ? path.split("\\") : [path]));
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");
try {
var lineReader = read.split("\n");
lineReader.forEach(function (line) {
// Parsing functions:
exports.Indexer.parseFunction(line, fileName);
// Parsing properties:
exports.Indexer.parseProperty(line, fileName);
// Check for uses
exports.Indexer.parseUse(line, fileName);
});
} catch (err) {
console.error(err);
}
var lineReader = read.split(/(\r|\n)/gim);
lineReader.forEach(function(line) {
// Parsing functions:
exports.Indexer.parseFunction(line, fileName);
// Parsing properties:
exports.Indexer.parseProperty(line, fileName);
// Check for uses
exports.Indexer.parseUse(line, fileName);
});
}
});
},
@ -316,8 +310,7 @@ exports.Indexer = {
var stat = fs.lstatSync(filename);
if (stat.isDirectory()) {
results = results.concat(exports.Indexer.findFilesInDir(filename, filter)); //recurse
}
else if (filename.indexOf(filter) >= 0) {
} else if (filename.indexOf(filter) >= 0) {
results.push(filename);
}
}
@ -325,11 +318,11 @@ exports.Indexer = {
},
/**
* Parses and exports.Indexer functions from a line.
* @param {String} line
* @param {String} fileName
*/
/**
* Parses and exports.Indexer functions from a line.
* @param {String} line
* @param {String} 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
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,
"static": false
};
functionModifiersLitteral.forEach(function (modifier) {
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) {
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.
});
@ -375,14 +368,14 @@ exports.Indexer = {
},
/**
* Parses and exports.Indexer uses from a line.
* @param {String} line
* @param {String} fileName
*/
/**
* Parses and exports.Indexer uses from a line.
* @param {String} line
* @param {String} fileName
*/
parseUse(line, fileName) {
var includeRegex = /use\s+((\w+\\)*)(\w+)(\s+as\s+(\w+)\s*)?;/;
match = includeRegex.exec(line);
var match = includeRegex.exec(line);
if (match) {
// Check if there is a match of "as" to set it.
var classType = '';
@ -396,18 +389,18 @@ exports.Indexer = {
},
/**
* Parses and exports Indexer properties (also static one) from a line.
* @param {String} line
* @param {String} fileName
*/
/**
* Parses and exports Indexer properties (also static one) from a line.
* @param {String} line
* @param {String} fileName
*/
parseProperty(line, fileName) {
var propertiesRegexr = /(protected|private|public|static|const)\s+(\$)?([\w_]+)\s*(;|=)/;
match = propertiesRegexr.exec(line);
var match = propertiesRegexr.exec(line);
if (match) {
if(match[1] == "static" && match[2] == "$") {
if (match[1] == "static" && match[2] == "$") {
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];
} else {
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",
"displayName": "PocketMine IDE",
"description": "Implementation of external PocketMine/PHP libs for Visual Studio Code",
"version": "0.0.4",
"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": {
"postinstall": "node ./node_modules/vscode/bin/install"
},
"devDependencies": {
"vscode": "^1.0.0",
"mocha": "^2.3.3",
"@types/node": "^6.0.40",
"@types/mocha": "^2.2.32"
},
"__metadata": {
"id": "2282a6db-6533-4359-8697-10ccdd4a97de",
"publisherId": "96452d5f-7333-47a6-9960-9cf179d6f173",
"publisherDisplayName": "Ad5001"
}
"name": "pocketmine-ide",
"displayName": "PocketMine IDE",
"description": "Implementation of external PocketMine/PHP libs for Visual Studio Code",
"version": "0.0.5",
"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": {
"postinstall": "node ./node_modules/vscode/bin/install"
},
"devDependencies": {
"vscode": "^1.0.0",
"mocha": "^2.3.3",
"@types/node": "^6.0.40",
"@types/mocha": "^2.2.32"
},
"__metadata": {
"id": "2282a6db-6533-4359-8697-10ccdd4a97de",
"publisherId": "96452d5f-7333-47a6-9960-9cf179d6f173",
"publisherDisplayName": "Ad5001"
}
}