From fe83896e34b40e93141165411a214c29454ef345 Mon Sep 17 00:00:00 2001 From: nevada_scout Date: Fri, 28 Oct 2016 20:04:21 +0100 Subject: [PATCH 1/9] Added "what's new" section to readme --- client/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/client/README.md b/client/README.md index 1c69717..835128d 100644 --- a/client/README.md +++ b/client/README.md @@ -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) + +- 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)_ From 712313c48e08a8b2cff844f04c16f9e80fcd86b7 Mon Sep 17 00:00:00 2001 From: nevada_scout Date: Fri, 28 Oct 2016 20:30:10 +0100 Subject: [PATCH 2/9] Added setting to allow the parser to ignore files --- client/README.md | 2 +- client/package.json | 5 +++++ client/src/utils/Config.ts | 5 +++++ client/src/utils/Cranefs.ts | 3 +++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/client/README.md b/client/README.md index 835128d..af99bc7 100644 --- a/client/README.md +++ b/client/README.md @@ -20,7 +20,7 @@ For the best development experience, make sure you have the PHP linter enabled i ## What's new in v0.2.2 (latest release) -- Ability to ignore files/folders for parsing (workaround for parser crashing issue) +- 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 --- diff --git a/client/package.json b/client/package.json index 9b3002f..f5e8831 100644 --- a/client/package.json +++ b/client/package.json @@ -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)" } } }, diff --git a/client/src/utils/Config.ts b/client/src/utils/Config.ts index 066e45d..32c2184 100644 --- a/client/src/utils/Config.ts +++ b/client/src/utils/Config.ts @@ -31,6 +31,11 @@ export class Config { return Config.craneSettings ? Config.craneSettings.get("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 { + Config.reloadConfig(); + return Config.craneSettings ? Config.craneSettings.get>("ignoredPaths", []) : []; + } + public static get version(): string { return pkg.version.toString(); } diff --git a/client/src/utils/Cranefs.ts b/client/src/utils/Cranefs.ts index e035247..1fee34e 100644 --- a/client/src/utils/Cranefs.ts +++ b/client/src/utils/Cranefs.ts @@ -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...`); From 27861495d02e1b2e0f17c010585ba4787f5dba98 Mon Sep 17 00:00:00 2001 From: nevada_scout Date: Fri, 28 Oct 2016 20:34:06 +0100 Subject: [PATCH 3/9] Update version number for 0.2.2 release --- client/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/package.json b/client/package.json index f5e8831..0fb42b5 100644 --- a/client/package.json +++ b/client/package.json @@ -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" From 5b8f7b278e9b2b62b46555032aefaac6db062ddf Mon Sep 17 00:00:00 2001 From: nevada_scout Date: Fri, 28 Oct 2016 20:58:20 +0100 Subject: [PATCH 4/9] Remove readme file --- README.md | 77 ------------------------------------------------------- 1 file changed, 77 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index 1c69717..0000000 --- a/README.md +++ /dev/null @@ -1,77 +0,0 @@ -# Crane - PHP code-completion for VS Code - -Crane is a productivity enhancement extension for [Visual Studio Code](http://code.visualstudio.com) that provides code-completion for PHP. It has zero dependencies and largely works with projects of any size. It is still in development, and as such there may be bugs and/or missing features. - -Please report any bugs that you find in our [issue tracker on GitHub](https://github.com/HvyIndustries/crane/issues). - -Follow [@HvyIndustries](https://twitter.com/HvyIndustries) on Twitter for updates! - -## How To Get Started - -1. Install Crane by pressing F1 in VS Code, then typing `ext install crane` -2. Open a PHP project -3. Check the status bar at the bottom and watch Crane parse all the PHP files it finds - -- Optionally, install the PHP Stubs to get code-completion for the built in PHP classes by pressing F1 in VS Code, then typing `crane php stubs` and selecting the appropriate option from the list. - -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`! - -## Current Features - -- Code-completion _(in progress, not quite 100% complete yet)_ - - For user created code - - Optionally for built-in PHP functions and classes (such as PDO) - -## Planned Features: - -* **Go to definition** (pressing F12) -* **Find references** -* Signature provider to show method parameter suggestions -* Hover provider to show information about symbol under the cursor -* Peek definition -* List symbols -* PhpDoc support (both for reading and writing documentation) - -## User Feedback - -> **Another total must have for PHP developers using Visual Studio Code.** -> Jan Hajek - -> **Essential extension for every PHP developer, just install :)** -> Marcelo Rodrigo - -> **Essential to every PHP developer, recommended!** -> Gabriel Coronado - -> That's the tweet I've been waiting for since the first public release of VS Code. Thanks. -> [Bruno Baketaric](https://twitter.com/laphblog/status/719631906598449152) - -> omg omg omg omg omg -> [Rich Perez](https://twitter.com/imperez/status/719645661461921793) - -> 👌👌👌 super awesome. -> [яєαℓιѕт נανѕтαн](https://twitter.com/RHJOfficial/status/719630044310740992) - -## Demo - -![](http://i.imgur.com/7128zNV.png) -![](http://i.imgur.com/CT2S3yX.gif) - -## Known Issues - -* There may be duplicate suggestions for functions or variables. This is because VS Code has it's own (very limited) code-completion support for PHP, and there is currently no way to turn this off. -* There can be strange behaviour when working with PHP and HTML in the same file. -* If you have a syntax error in a file, you may not get a full list of suggestions for that file. - -## Links - -* [Repository](https://github.com/HvyIndustries/crane) -* [VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=HvyIndustries.crane) - - -**[Please report any bugs you find!](https://github.com/HvyIndustries/crane/issues)** - - -*"HVY", "HVY Industries" and "Hvy Industries" are trading names of JCKD (UK) Ltd* - -*Icon by http://icons8.com/* From 034d063f057918a6000d3ab30b9d0d1e7c2642b5 Mon Sep 17 00:00:00 2001 From: nevada_scout Date: Fri, 28 Oct 2016 20:58:31 +0100 Subject: [PATCH 5/9] Add symlinked readme file --- README.md | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..af99bc7 --- /dev/null +++ b/README.md @@ -0,0 +1,86 @@ +# Crane - PHP code-completion for VS Code + +Crane is a productivity enhancement extension for [Visual Studio Code](http://code.visualstudio.com) that provides code-completion for PHP. It has zero dependencies and largely works with projects of any size. It is still in development, and as such there may be bugs and/or missing features. + +Please report any bugs that you find in our [issue tracker on GitHub](https://github.com/HvyIndustries/crane/issues). + +Follow [@HvyIndustries](https://twitter.com/HvyIndustries) on Twitter for updates! + +## How To Get Started + +1. Install Crane by pressing F1 in VS Code, then typing `ext install crane` +2. Open a PHP project +3. Check the status bar at the bottom and watch Crane parse all the PHP files it finds + +- Optionally, install the PHP Stubs to get code-completion for the built in PHP classes by pressing F1 in VS Code, then typing `crane php stubs` and selecting the appropriate option from the list. + +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)_ + - For user created code + - Optionally for built-in PHP functions and classes (such as PDO) + +## Planned Features: + +* **Go to definition** (pressing F12) +* **Find references** +* Signature provider to show method parameter suggestions +* Hover provider to show information about symbol under the cursor +* Peek definition +* List symbols +* PhpDoc support (both for reading and writing documentation) + +## User Feedback + +> **Another total must have for PHP developers using Visual Studio Code.** +> Jan Hajek + +> **Essential extension for every PHP developer, just install :)** +> Marcelo Rodrigo + +> **Essential to every PHP developer, recommended!** +> Gabriel Coronado + +> That's the tweet I've been waiting for since the first public release of VS Code. Thanks. +> [Bruno Baketaric](https://twitter.com/laphblog/status/719631906598449152) + +> omg omg omg omg omg +> [Rich Perez](https://twitter.com/imperez/status/719645661461921793) + +> 👌👌👌 super awesome. +> [яєαℓιѕт נανѕтαн](https://twitter.com/RHJOfficial/status/719630044310740992) + +## Demo + +![](http://i.imgur.com/7128zNV.png) +![](http://i.imgur.com/CT2S3yX.gif) + +## Known Issues + +* There may be duplicate suggestions for functions or variables. This is because VS Code has it's own (very limited) code-completion support for PHP, and there is currently no way to turn this off. +* There can be strange behaviour when working with PHP and HTML in the same file. +* If you have a syntax error in a file, you may not get a full list of suggestions for that file. + +## Links + +* [Repository](https://github.com/HvyIndustries/crane) +* [VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=HvyIndustries.crane) + + +**[Please report any bugs you find!](https://github.com/HvyIndustries/crane/issues)** + + +*"HVY", "HVY Industries" and "Hvy Industries" are trading names of JCKD (UK) Ltd* + +*Icon by http://icons8.com/* From bdd60ff690e7d6c2039265b798c39df3e9bd3d04 Mon Sep 17 00:00:00 2001 From: Dimitar Dimitrov Date: Fri, 16 Dec 2016 15:15:55 +0200 Subject: [PATCH 6/9] Populate the namespace property for traits and interfaces --- server/src/hvy/treeBuilder.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/server/src/hvy/treeBuilder.ts b/server/src/hvy/treeBuilder.ts index 50a5609..59f0a58 100644 --- a/server/src/hvy/treeBuilder.ts +++ b/server/src/hvy/treeBuilder.ts @@ -252,6 +252,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 => { @@ -309,6 +317,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(); From e1ab050f40310aab6daafd80bf6a112da7749eb3 Mon Sep 17 00:00:00 2001 From: Dimitar Dimitrov Date: Fri, 16 Dec 2016 15:18:13 +0200 Subject: [PATCH 7/9] Prevent exception on completion for use statements There was an exception here with 'trying to get index 0 of undefined' most of the times while auto completing --- server/src/hvy/treeBuilder.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/src/hvy/treeBuilder.ts b/server/src/hvy/treeBuilder.ts index 59f0a58..439207d 100644 --- a/server/src/hvy/treeBuilder.ts +++ b/server/src/hvy/treeBuilder.ts @@ -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]; From 7754b6ca4b943205651b9f52785bcf26cd2b5616 Mon Sep 17 00:00:00 2001 From: Dimitar Dimitrov Date: Fri, 16 Dec 2016 15:20:51 +0200 Subject: [PATCH 8/9] Make completion suggestions fluent to the context they are used in - Should suggest only classes when 'new' is preceeding the call; and - Should suggest only classes when 'extends' is before the current position of the cursor (before 'implements') - Should suggest only interfaces when the cursor is after a 'implements' key word --- server/src/suggestionBuilder.ts | 41 +++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/server/src/suggestionBuilder.ts b/server/src/suggestionBuilder.ts index 1b35cc4..b1c9b8d 100644 --- a/server/src/suggestionBuilder.ts +++ b/server/src/suggestionBuilder.ts @@ -268,24 +268,55 @@ 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.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.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.join('\\') + '\\' + item.name + }); }); } }); - return toReturn; + return toReturn.filter((item) => { + if (this.currentLine.indexOf('new') !== -1 || this.currentLine.indexOf('extends') !== -1 && (this.currentLine.indexOf('extends') < this.charIndex)) { + return item.kind === CompletionItemKind.Class; + } + + if (this.currentLine.indexOf('implements') !== -1 && (this.currentLine.indexOf('implements') < this.charIndex)) { + return item.kind === CompletionItemKind.Interface; + } + + return true; + }); } private getScope() : Scope @@ -689,4 +720,4 @@ enum ScopeLevel Class, Interface, Trait -} \ No newline at end of file +} From a66d81591746a1f601b7f173729955a740487dd8 Mon Sep 17 00:00:00 2001 From: Dimitar Dimitrov Date: Fri, 16 Dec 2016 16:02:05 +0200 Subject: [PATCH 9/9] Imroved fluency of the suggestions - Should not insert namespace separator when using in use statements for the current file - Should avoid conflicts whith variables/methods which contain the keywords 'new', 'implements', 'extends' and 'use' somewhere in their names --- server/src/suggestionBuilder.ts | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/server/src/suggestionBuilder.ts b/server/src/suggestionBuilder.ts index b1c9b8d..47bd4dd 100644 --- a/server/src/suggestionBuilder.ts +++ b/server/src/suggestionBuilder.ts @@ -274,7 +274,9 @@ export class SuggestionBuilder detail: '\\' + item.namespaceParts.join('\\'), insertText: (this.doc.getText().indexOf('use ' + item.namespaceParts.join('\\') + '\\' + item.name + ';') !== -1) ? - item.name : item.namespaceParts.join('\\') + '\\' + item.name + item.name : (item.namespaceParts.length > 0 ? ( + this.currentLine.indexOf('use ') !== 0 ? '\\' : '' + ) + item.namespaceParts.join('\\') : '') + '\\'+ item.name }); }); } @@ -287,7 +289,9 @@ export class SuggestionBuilder detail: '\\' + item.namespace.join('\\'), insertText: (this.doc.getText().indexOf('use ' + item.namespace.join('\\') + '\\' + item.name + ';') !== -1) ? - item.name : item.namespace.join('\\') + '\\' + item.name + item.name : (item.namespace.length > 0 ? ( + this.currentLine.indexOf('use ') !== 0 ? '\\' : '' + ) + item.namespace.join('\\') : '') + '\\'+ item.name }); }); } @@ -300,21 +304,35 @@ export class SuggestionBuilder detail: '\\' + item.namespaceParts.join('\\'), insertText: (this.doc.getText().indexOf('use ' + item.namespaceParts.join('\\') + '\\' + item.name + ';') !== -1) ? - item.name : item.namespaceParts.join('\\') + '\\' + item.name + item.name : (item.namespaceParts.length > 0 ? ( + this.currentLine.indexOf('use ') !== 0 ? '\\' : '' + ) + item.namespaceParts.join('\\') : '') + '\\'+ item.name }); }); } }); return toReturn.filter((item) => { - if (this.currentLine.indexOf('new') !== -1 || this.currentLine.indexOf('extends') !== -1 && (this.currentLine.indexOf('extends') < this.charIndex)) { + if (this.currentLine.indexOf(' new ') !== -1 || this.currentLine.indexOf(' extends ') !== -1 && (this.currentLine.indexOf(' extends ') < this.charIndex)) { return item.kind === CompletionItemKind.Class; } - if (this.currentLine.indexOf('implements') !== -1 && (this.currentLine.indexOf('implements') < this.charIndex)) { + if (this.currentLine.indexOf(' implements ') !== -1 && (this.currentLine.indexOf(' implements ') < this.charIndex)) { return item.kind === CompletionItemKind.Interface; } + if (this.currentLine.indexOf(' use ') === 0) { + return item.kind === CompletionItemKind.Module; + } + + /** + * This prevents issues where suggestions hould be there but are not + * like when assigning the result of a static method call to a variable, + * looking for '=' on the line is a bit risky and might lead to poor + * suggestions, also another case is when typehinting the function/method + * arguments. + */ + return true; }); }