Skip to content
This repository has been archived by the owner on Jul 22, 2019. It is now read-only.

Improve completion class/interface/trait completion #195

9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ Follow [@HvyIndustries](https://twitter.com/HvyIndustries) on Twitter for update

For the best development experience, make sure you have the PHP linter enabled in your user settings, and set it to run `onType` instead of `onSave`!

---

## What's new in v0.2.2 (latest release)

- Added new setting `crane.ignoredPaths` that gives users the ability to ignore files/folders for parsing _(workaround for parser crashing issue)_
- Added "what's new" section to readme to highlight new features/bug fixes

---

## Current Features

- Code-completion _(in progress, not quite 100% complete yet)_
Expand Down
9 changes: 9 additions & 0 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ Follow [@HvyIndustries](https://twitter.com/HvyIndustries) on Twitter for update

For the best development experience, make sure you have the PHP linter enabled in your user settings, and set it to run `onType` instead of `onSave`!

---

## What's new in v0.2.2 (latest release)

- Added new setting `crane.ignoredPaths` that gives users the ability to ignore files/folders for parsing _(workaround for parser crashing issue)_
- Added "what's new" section to readme to highlight new features/bug fixes

---

## Current Features

- Code-completion _(in progress, not quite 100% complete yet)_
Expand Down
7 changes: 6 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"icon": "images/php-256.png",
"license": "MIT",
"version": "0.2.1",
"version": "0.2.2",
"publisher": "HvyIndustries",
"engines": {
"vscode": "^0.10.x"
Expand Down Expand Up @@ -70,6 +70,11 @@
"type": "string",
"default": "https://codeload.github.com/HvyIndustries/crane-php-stubs/zip/master",
"description": "The location of the PHP Stubs zip file that can be downloaded and unzipped for 3rd party library autocompletion"
},
"crane.ignoredPaths": {
"type": "array",
"default": [],
"description": "An array of files/folders that should be ignored by the parser. Glob patterns are accepted (eg. **/*bad.php)"
}
}
},
Expand Down
5 changes: 5 additions & 0 deletions client/src/utils/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export class Config {
return Config.craneSettings ? Config.craneSettings.get<string>("phpstubsZipFile", "https://codeload.github.com/HvyIndustries/crane-php-stubs/zip/master") : "https://codeload.github.com/HvyIndustries/crane-php-stubs/zip/master";
}

public static get ignoredPaths(): Array<string> {
Config.reloadConfig();
return Config.craneSettings ? Config.craneSettings.get<Array<string>>("ignoredPaths", []) : [];
}

public static get version(): string {
return pkg.version.toString();
}
Expand Down
3 changes: 3 additions & 0 deletions client/src/utils/Cranefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ export class Cranefs {
// Get PHP files from 'files.associations' to be processed
var files = Config.phpFileTypes;

// Exclude files ignored by the user
files.exclude = files.exclude.concat(Config.ignoredPaths);

// Find all the php files to process
workspace.findFiles(`{${files.include.join(',')}}`, `{${files.exclude.join(',')}}`).then(files => {
Debug.info(`Preparing to parse ${files.length} PHP source files...`);
Expand Down
20 changes: 20 additions & 0 deletions server/src/hvy/treeBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ export class TreeBuilder
break;

case "const":
// this fixes exception when trying ot get completion on file `use` statements
if (branch[1][0] === undefined || branch[1][0][1] === undefined || branch[1][0][1][0] === undefined) {
break;
}
let constantNode: ConstantNode = new ConstantNode();
if (isset(branch[1][0][0] || false) && isset(branch[1][0][1][0] || false)) {
constantNode.name = branch[1][0][0];
Expand Down Expand Up @@ -252,6 +256,14 @@ export class TreeBuilder
});
}

if (parentBranches != null && parentBranches.length > 0)
{
// Add namespaces
parentBranches.forEach(item => {
interfaceNode.namespace.push(item);
});
}

// Build constants
branch[3][4].constants.forEach(constant =>
{
Expand Down Expand Up @@ -309,6 +321,14 @@ export class TreeBuilder
traitNode.extends = branch[3][2][0];
}

if (parentBranches != null && parentBranches.length > 0)
{
// Add namespaces
parentBranches.forEach(item => {
traitNode.namespaceParts.push(item);
});
}

branch[3][4].properties.forEach(propLevel =>
{
let propNode: PropertyNode = new PropertyNode();
Expand Down
59 changes: 54 additions & 5 deletions server/src/suggestionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,24 +268,73 @@ export class SuggestionBuilder
this.workspaceTree.forEach(fileNode => {
if (options.classes) {
fileNode.classes.forEach(item => {
toReturn.push({ label: item.name, kind: CompletionItemKind.Class, detail: "(class)" });
toReturn.push({
label: item.name,
kind: CompletionItemKind.Class,
detail: '\\' + item.namespaceParts.join('\\'),
insertText:
(this.doc.getText().indexOf('use ' + item.namespaceParts.join('\\') + '\\' + item.name + ';') !== -1) ?
item.name : (item.namespaceParts.length > 0 ? (
this.currentLine.indexOf('use ') !== 0 ? '\\' : ''
) + item.namespaceParts.join('\\') : '') + '\\'+ item.name
});
});
}

if (options.interfaces) {
fileNode.interfaces.forEach(item => {
toReturn.push({ label: item.name, kind: CompletionItemKind.Interface, detail: "(interface)" });
toReturn.push({
label: item.name,
kind: CompletionItemKind.Interface,
detail: '\\' + item.namespace.join('\\'),
insertText:
(this.doc.getText().indexOf('use ' + item.namespace.join('\\') + '\\' + item.name + ';') !== -1) ?
item.name : (item.namespace.length > 0 ? (
this.currentLine.indexOf('use ') !== 0 ? '\\' : ''
) + item.namespace.join('\\') : '') + '\\'+ item.name
});
});
}

if (options.traits) {
fileNode.traits.forEach(item => {
toReturn.push({ label: item.name, kind: CompletionItemKind.Module, detail: "(trait)" });
toReturn.push({
label: item.name,
kind: CompletionItemKind.Module,
detail: '\\' + item.namespaceParts.join('\\'),
insertText:
(this.doc.getText().indexOf('use ' + item.namespaceParts.join('\\') + '\\' + item.name + ';') !== -1) ?
item.name : (item.namespaceParts.length > 0 ? (