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

Commit

Permalink
Merge pull request #170 from HvyIndustries/feature/improve-stability
Browse files Browse the repository at this point in the history
Merge feature/improve stability into master
  • Loading branch information
nevadascout authored Sep 26, 2016
2 parents 5f807d5 + e0d4f84 commit 4b7f552
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 70 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ For the best development experience, make sure you have the PHP linter enabled i
> **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)
Expand Down
6 changes: 6 additions & 0 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ For the best development experience, make sure you have the PHP linter enabled i
> **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)
Expand Down
Binary file added client/images/php-256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 9 additions & 4 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "crane",
"displayName": "Crane - PHP Intellisense",
"displayName": "PHP Intellisense - Crane",
"description": "PHP Intellisense/code-completion",
"author": {
"name": "Hvy Industries",
"url": "https://hvy.io",
"email": "[email protected]"
},
"icon": "images/icon.png",
"icon": "images/php-256.png",
"license": "MIT",
"version": "0.2.0",
"version": "0.2.1",
"publisher": "HvyIndustries",
"engines": {
"vscode": "^0.10.x"
Expand All @@ -28,6 +28,11 @@
],
"keywords": [
"php",
"php5",
"php7",
"crane",
"hvy",
"productivity",
"code-completion",
"intellisense"
],
Expand Down Expand Up @@ -113,7 +118,7 @@
"dependencies": {
"fstream": "^1.0.9",
"mkdirp": "^0.5.1",
"php-parser": "HvyIndustries/php-parser#faa51b7",
"php-parser": "HvyIndustries/php-parser#8820998",
"rimraf": "^2.5.2",
"unzip": "^0.1.11",
"vscode-languageclient": "^1.1.0"
Expand Down
16 changes: 12 additions & 4 deletions client/phpTest/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@

class Awesome
{
public $strProp = "string";
public $numProp = 14;
public $arrayProp = array();
public $arrayProp2 = array(
"test" => "test"
);
public $boolProp = TRuE;
public $nullProp = NULL;

/**
* @param string $param1
* @param string $param2
* @return Awesome2
*/
public static function test($param1, Awesome $param2, $p2 = 'cat')
{
$t = new Awesome();
return new Awesome2();
}

Expand All @@ -27,13 +37,11 @@ class Awesome2
public function ha(Awesome $a)
{
$a->test();

echo "$test->test->test";
echo "{$test->test}->test";
}

public function he()
{
$db = new PDO();
}

}
}
2 changes: 1 addition & 1 deletion client/src/crane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export default class Crane
let delayer = this.delayers[key];

if (!delayer) {
delayer = new ThrottledDelayer<void>(250);
delayer = new ThrottledDelayer<void>(500);
this.delayers[key] = delayer;
}

Expand Down
Binary file added images/php-256.fw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/php-256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/php.fw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/php.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "crane-lang-server",
"description": "The language server for Crane",
"version": "1.0.1",
"version": "1.0.2",
"author": "HVY Industries",
"license": "MIT",
"engines": {
Expand All @@ -14,7 +14,7 @@
"dependencies": {
"filequeue": "^0.5.0",
"glob": "7.0.3",
"php-parser": "HvyIndustries/php-parser#faa51b7",
"php-parser": "HvyIndustries/php-parser#8820998",
"vscode-languageserver": "^1.1.0"
},
"devDependencies": {
Expand Down
135 changes: 78 additions & 57 deletions server/src/hvy/treeBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ export class TreeBuilder
});
}

public Ping(): string
{
return "pong";
}

// Convert the generated AST into a usable object tree
private BuildObjectTree(ast, filePath:string) : Promise<FileNode>
{
Expand Down Expand Up @@ -193,31 +198,33 @@ export class TreeBuilder

branch[3][6].forEach(codeLevel =>
{
// Build local scope variable setters
let scopeVar = this.BuildVariableOrProp(codeLevel);
if (scopeVar != null) {
methodNode.scopeVariables.push(scopeVar.variableNode);
if (scopeVar.lineCache != null) {
tree.lineCache.push(scopeVar.lineCache);
if (codeLevel != null) {
// Build local scope variable setters
let scopeVar = this.BuildVariableOrProp(codeLevel);
if (scopeVar != null) {
methodNode.scopeVariables.push(scopeVar.variableNode);
if (scopeVar.lineCache != null) {
tree.lineCache.push(scopeVar.lineCache);
}
}
}

// Build function calls
let functionCalls = this.BuildFunctionCallsToOtherFunctions(codeLevel);
functionCalls.forEach(element => {
methodNode.functionCalls.push(element);
});
// Build function calls
let functionCalls = this.BuildFunctionCallsToOtherFunctions(codeLevel);
functionCalls.forEach(element => {
methodNode.functionCalls.push(element);
});

// Build imported global variables
if (codeLevel[0] == "global")
{
codeLevel[1].forEach(importGlobalLevel =>
// Build imported global variables
if (codeLevel[0] == "global")
{
if (importGlobalLevel[0] == "var")
codeLevel[1].forEach(importGlobalLevel =>
{
methodNode.globalVariables.push(importGlobalLevel[1]);
}
});
if (importGlobalLevel[0] == "var")
{
methodNode.globalVariables.push(importGlobalLevel[1]);
}
});
}
}
});

Expand Down Expand Up @@ -463,27 +470,38 @@ export class TreeBuilder
propNode.isStatic = true;
}

propLevel = propLevel[3][0];
propNode.name = propLevel[3][0];
if (propLevel[3][0] != null) {
propLevel = propLevel[3][0];
propNode.name = propLevel[3][0];

if (propLevel[3][1] != null) {
let type = propLevel[3][1][0];
if (type == "string" || type == "number") {
propNode.type = type;
//propNode.value = codeLevel[3][1][1];
} else if (type == "const") {
propNode.type = "boolean";
//propNode.value = codeLevel[2][1];
if (propLevel[3][1] != null) {
let type = propLevel[3][1][0];

if (type == "position") {
type = propLevel[3][1][3][0];
}

if (type == "string" || type == "number" || type == "array") {
propNode.type = type;
//propNode.value = codeLevel[3][1][1];
} else if (type == "const") {
if (propLevel[3][1][1][0].toLowerCase() == "true" || propLevel[3][1][1][0].toLowerCase() == "false") {
propNode.type = "boolean";
} else if (propLevel[3][1][1][0].toLowerCase() == "null") {
propNode.type = "null";
}
//propNode.value = codeLevel[2][1];
}
}
}

var symbolCache = new FileSymbolCache();
symbolCache.name = propNode.name;
symbolCache.type = SymbolType.Property;
symbolCache.parentName = classNode.name;
tree.symbolCache.push(symbolCache);
var symbolCache = new FileSymbolCache();
symbolCache.name = propNode.name;
symbolCache.type = SymbolType.Property;
symbolCache.parentName = classNode.name;
tree.symbolCache.push(symbolCache);

classNode.properties.push(propNode);
classNode.properties.push(propNode);
}
});

// Build constants
Expand Down Expand Up @@ -533,31 +551,34 @@ export class TreeBuilder
{
methodLevel[3][6].forEach(codeLevel =>
{
// Build local scope variable setters
let scopeVar = this.BuildVariableOrProp(codeLevel);
if (scopeVar != null) {
constructorNode.scopeVariables.push(scopeVar.variableNode);
if (scopeVar.lineCache != null) {
tree.lineCache.push(scopeVar.lineCache);
if (codeLevel != null)
{
// Build local scope variable setters
let scopeVar = this.BuildVariableOrProp(codeLevel);
if (scopeVar != null) {
constructorNode.scopeVariables.push(scopeVar.variableNode);
if (scopeVar.lineCache != null) {
tree.lineCache.push(scopeVar.lineCache);
}
}
}

// Build function calls
let functionCalls = this.BuildFunctionCallsToOtherFunctions(codeLevel);
functionCalls.forEach(element => {
constructorNode.functionCalls.push(element);
});
// Build function calls
let functionCalls = this.BuildFunctionCallsToOtherFunctions(codeLevel);
functionCalls.forEach(element => {
constructorNode.functionCalls.push(element);
});

// Build imported global variables
if (codeLevel[0] == "global")
{
codeLevel[1].forEach(importGlobalLevel =>
// Build imported global variables
if (codeLevel[0] == "global")
{
if (importGlobalLevel[0] == "var")
codeLevel[1].forEach(importGlobalLevel =>
{
constructorNode.globalVariables.push(importGlobalLevel[1]);
}
});
if (importGlobalLevel[0] == "var")
{
constructorNode.globalVariables.push(importGlobalLevel[1]);
}
});
}
}
});
}
Expand Down
6 changes: 6 additions & 0 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ let treeBuilder: TreeBuilder = new TreeBuilder();
treeBuilder.SetConnection(connection);
let workspaceTree: FileNode[] = [];

// Prevent garbage collection of essential objects
let timer = setInterval(() => {
treeBuilder.Ping();
return workspaceTree.length;
}, 15000);

let workspaceRoot: string;
var craneProjectDir: string;
let enableCache: boolean = true;
Expand Down
17 changes: 15 additions & 2 deletions server/src/suggestionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ export class SuggestionBuilder
})[0];
}

private isSelf(): boolean
{
if (this.currentLine.substr(this.charIndex - 6, this.charIndex - 1) == "self::") {
return true;
}

if (this.currentLine.substr(this.charIndex - 8, this.charIndex - 1) == "static::") {
return true;
}

return false;
}

public build() : CompletionItem[]
{
var scope = this.getScope();
Expand All @@ -59,7 +72,7 @@ export class SuggestionBuilder
if (this.lastChar == ">") {
toReturn = toReturn.concat(this.checkAccessorAndAddMembers(scope));
} else if (this.lastChar == ":") {
if (this.currentLine.substr(this.charIndex - 6, this.charIndex - 1) == "self::") {
if (this.isSelf()) {
// Accessing via self::
this.currentFileNode.classes.forEach(classNode => {
if (this.withinBlock(classNode)) {
Expand All @@ -70,7 +83,7 @@ export class SuggestionBuilder
} else {
// Probably accessing via [ClassName]::
var classNames = this.currentLine.trim().match(/\S(\B[a-z]+?)(?=::)/ig);
if (classNames.length > 0) {
if (classNames && classNames.length > 0) {
var className = classNames[classNames.length - 1];
var classNode = this.getClassNodeFromTree(className);
if (classNode != null) {
Expand Down

0 comments on commit 4b7f552

Please sign in to comment.