0.0.5 - Fixing some bugs

This commit is contained in:
Ad5001 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

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

@ -99,7 +99,7 @@ function activate(context) {
*/
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);

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

@ -218,10 +218,11 @@ 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") {
newSuggestion.insertText = currentClass.split("\\")[currentClass.split("\\").length - 1];
@ -255,28 +256,23 @@ exports.Indexer = {
}
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] = {};
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");
var lineReader = read.split(/(\r|\n)/gim);
lineReader.forEach(function(line) {
// Parsing functions:
exports.Indexer.parseFunction(line, fileName);
@ -285,9 +281,7 @@ exports.Indexer = {
// Check for uses
exports.Indexer.parseUse(line, fileName);
});
} catch (err) {
console.error(err);
}
}
});
},
@ -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);
}
}
@ -382,7 +375,7 @@ exports.Indexer = {
*/
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 = '';
@ -403,7 +396,7 @@ exports.Indexer = {
*/
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] == "$") {
exports.Indexer.phpFileProperties[fileName][match[3]] = [match[3], PROPERTY_STATIC];

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;

5
package.json Normal file → Executable file
View file

@ -2,7 +2,7 @@
"name": "pocketmine-ide",
"displayName": "PocketMine IDE",
"description": "Implementation of external PocketMine/PHP libs for Visual Studio Code",
"version": "0.0.4",
"version": "0.0.5",
"publisher": "Ad5001",
"homepage": "https://github.com/Ad5001/PocketMine-IDE",
"keywords": [
@ -31,8 +31,7 @@
],
"main": "./out/src/extension",
"contributes": {
"commands": [
{
"commands": [{
"command": "pmide.indexPhpFiles",
"title": "PocketMine IDE - Index PHP Files"
},