2017-06-28 09:15:35 +00:00
|
|
|
/**
|
|
|
|
* Main file for extension
|
|
|
|
* Almost entiry rewritten by (C) Ad5001 2017
|
|
|
|
*/
|
|
|
|
|
2017-04-30 16:08:58 +00:00
|
|
|
'use strict';
|
|
|
|
const vscode = require('vscode');
|
2017-06-28 09:15:35 +00:00
|
|
|
// const phpFuncSuggestion = require('./phpFunctionSuggestions');
|
|
|
|
const Indexer = (require('./phpCompletionItem')).Indexer;
|
2017-04-30 16:08:58 +00:00
|
|
|
exports.PHP_MODE = { language: 'php', scheme: 'file' };
|
2017-06-28 09:15:35 +00:00
|
|
|
exports.currentPath = "";
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initial extension activation
|
|
|
|
*
|
|
|
|
* @param {*} context
|
|
|
|
*/
|
2017-04-30 16:08:58 +00:00
|
|
|
function activate(context) {
|
|
|
|
// Do the initial indexing
|
2017-06-28 09:15:35 +00:00
|
|
|
Indexer.indexPhpFiles();
|
|
|
|
|
|
|
|
// require("fs").appendFileSync("/home/ad5001/echo.txt", JSON.stringify(Indexer.phpFileProperties))
|
|
|
|
vscode.workspace.onDidSaveTextDocument(function (document) {
|
|
|
|
Indexer.indexPhpFiles();
|
2017-04-30 16:08:58 +00:00
|
|
|
});
|
2017-06-28 09:15:35 +00:00
|
|
|
|
2017-04-30 16:08:58 +00:00
|
|
|
// Setup our class as a compvarion item provider for function autocompvare
|
2017-05-01 08:32:28 +00:00
|
|
|
context.subscriptions.push(vscode.languages.registerCompletionItemProvider(exports.PHP_MODE, {
|
2017-04-30 16:08:58 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-06-28 09:15:35 +00:00
|
|
|
// Checking for commun regexps
|
2017-04-30 16:08:58 +00:00
|
|
|
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);
|
2017-06-28 09:15:35 +00:00
|
|
|
var classInFunc = /(\(|,\s*)((\\\w+)+)/.exec(lineText);
|
|
|
|
|
2017-04-30 16:08:58 +00:00
|
|
|
// 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 = [];
|
2017-06-28 09:15:35 +00:00
|
|
|
|
2017-04-30 16:08:58 +00:00
|
|
|
// 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/", "");
|
2017-06-28 09:15:35 +00:00
|
|
|
|
2017-04-30 16:08:58 +00:00
|
|
|
// Look through all included/required files for the current document
|
2017-06-28 09:15:35 +00:00
|
|
|
for (var f in Indexer.phpFileFunctions) {
|
2017-04-30 16:08:58 +00:00
|
|
|
// Checking normal functions
|
2017-06-28 09:15:35 +00:00
|
|
|
if (execute) {
|
|
|
|
suggestions = Indexer.getFunctionsFromFile(f, suggestions, currentWord, execute);
|
|
|
|
suggestions = Indexer.getPropertiesFromFile(f, suggestions, currentWord, execute);
|
|
|
|
}
|
|
|
|
|
2017-04-30 16:08:58 +00:00
|
|
|
// Checking static functions
|
2017-06-28 09:15:35 +00:00
|
|
|
if (executeStatic) {
|
|
|
|
suggestions = Indexer.getStaticFunctionsFromFile(f, suggestions, currentWord, executeStatic);
|
|
|
|
suggestions = Indexer.getStaticPropertiesFromFile(f, suggestions, currentWord, executeStatic);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Checking for class name
|
2017-04-30 16:08:58 +00:00
|
|
|
if (f.indexOf(currentWord) > 0) {
|
2017-06-28 09:15:35 +00:00
|
|
|
// New instance
|
|
|
|
if (clas && (clas[2] == currentWord || clas[3] == "\\" + currentWord)) {
|
|
|
|
suggestions = Indexer.getClassNew(f, suggestions, currentPath, clas);
|
2017-04-30 16:08:58 +00:00
|
|
|
} else if (use && (use[1] == currentWord || use[2] == "\\" + currentWord)) { // Use
|
2017-06-28 09:15:35 +00:00
|
|
|
suggestions = Indexer.getClassUse(f, suggestions);
|
2017-04-30 16:08:58 +00:00
|
|
|
} else if (!(execute && execute[1] == currentWord) && !(executeStatic && executeStatic[1] == currentWord)) { // static classes
|
2017-06-28 09:15:35 +00:00
|
|
|
suggestions = Indexer.getClassNormal(f, suggestions, currentPath);
|
2017-04-30 16:08:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2017-06-28 09:15:35 +00:00
|
|
|
Indexer.done = {};// Reseting cache
|
2017-04-30 16:08:58 +00:00
|
|
|
return suggestions;
|
|
|
|
}
|
|
|
|
}));
|
2017-06-28 09:15:35 +00:00
|
|
|
|
2017-04-30 16:08:58 +00:00
|
|
|
// Setup our plugin to help with function signatures
|
2017-06-28 09:15:35 +00:00
|
|
|
// context.subscriptions.push(vscode.languages.registerSignatureHelpProvider(exports.PHP_MODE, new phpFuncSuggestion.PhpSignatureHelpProvider(vscode.workspace.getConfiguration('php')['docsTool']), '(', ','));
|
|
|
|
|
|
|
|
// Commands registered by plugin
|
|
|
|
/**
|
|
|
|
* Reindex php files command
|
|
|
|
*/
|
|
|
|
var indexDisposable = vscode.commands.registerCommand('pmide.indexPhpFiles', function () {
|
|
|
|
Indexer.indexPhpFiles();
|
2017-04-30 16:08:58 +00:00
|
|
|
});
|
2017-06-28 09:15:35 +00:00
|
|
|
/**
|
|
|
|
* Prints everything about PHP files.
|
|
|
|
*/
|
|
|
|
var printDisposable = vscode.commands.registerCommand('pmide.printPhpFiles', function () {
|
|
|
|
console.log(Object.keys(Indexer.phpFileFunctions).length);
|
|
|
|
console.log(Indexer.phpFileUses);
|
2017-04-30 16:08:58 +00:00
|
|
|
});
|
|
|
|
context.subscriptions.push(indexDisposable);
|
|
|
|
context.subscriptions.push(printDisposable);
|
|
|
|
}
|
|
|
|
exports.activate = activate;
|
|
|
|
|
|
|
|
|
2017-06-28 09:15:35 +00:00
|
|
|
exports.deactivate = function () { };
|