Correct code style
parent
5f8e37be9e
commit
b99fb94840
|
@ -148,7 +148,7 @@ class LanguageServer extends \AdvancedJsonRpc\Dispatcher
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$duration = (int)(microtime(true) - $startTime);
|
$duration = (int)(microtime(true) - $startTime);
|
||||||
$mem = (int)(memory_get_usage(true)/(1024*1024));
|
$mem = (int)(memory_get_usage(true) / (1024 * 1024));
|
||||||
$this->client->window->logMessage(3, "All PHP files parsed in $duration seconds. $mem MiB allocated.");
|
$this->client->window->logMessage(3, "All PHP files parsed in $duration seconds. $mem MiB allocated.");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -72,8 +72,7 @@ class PhpDocument
|
||||||
$errors = [];
|
$errors = [];
|
||||||
try {
|
try {
|
||||||
$stmts = $this->parser->parse($this->content);
|
$stmts = $this->parser->parse($this->content);
|
||||||
}
|
} catch(\PhpParser\Error $e) {
|
||||||
catch(\PhpParser\Error $e) {
|
|
||||||
// Lexer can throw errors. e.g for unterminated comments
|
// Lexer can throw errors. e.g for unterminated comments
|
||||||
// unfortunately we don't get a location back
|
// unfortunately we don't get a location back
|
||||||
$errors[] = $e;
|
$errors[] = $e;
|
||||||
|
|
|
@ -47,7 +47,7 @@ class Project
|
||||||
public function getDocument(string $uri)
|
public function getDocument(string $uri)
|
||||||
{
|
{
|
||||||
$uri = urldecode($uri);
|
$uri = urldecode($uri);
|
||||||
if (!isset($this->documents[$uri])){
|
if (!isset($this->documents[$uri])) {
|
||||||
$this->documents[$uri] = new PhpDocument($uri, $this, $this->client, $this->parser);
|
$this->documents[$uri] = new PhpDocument($uri, $this, $this->client, $this->parser);
|
||||||
}
|
}
|
||||||
return $this->documents[$uri];
|
return $this->documents[$uri];
|
||||||
|
|
|
@ -84,5 +84,4 @@ class TextDocument
|
||||||
{
|
{
|
||||||
return $this->project->getDocument($textDocument->uri)->getFormattedText();
|
return $this->project->getDocument($textDocument->uri)->getFormattedText();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,12 +39,12 @@ class SymbolFinder extends NodeVisitorAbstract
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $nameStack = array();
|
private $nameStack = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $nodeStack = array();
|
private $nodeStack = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
|
@ -58,26 +58,21 @@ class SymbolFinder extends NodeVisitorAbstract
|
||||||
|
|
||||||
public function enterNode(Node $node)
|
public function enterNode(Node $node)
|
||||||
{
|
{
|
||||||
array_push($this->nodeStack, $node);
|
$this->nodeStack[] = $node;
|
||||||
$containerName = end($this->nameStack);
|
$containerName = end($this->nameStack);
|
||||||
|
|
||||||
// If we enter a named node, push its name onto name stack.
|
// If we enter a named node, push its name onto name stack.
|
||||||
// Else push the current name onto stack.
|
// Else push the current name onto stack.
|
||||||
if (!empty($node->name) && (is_string($node->name) || method_exists($node->name, '__toString')) && !empty((string)$node->name)) {
|
if (!empty($node->name) && !empty((string)$node->name)) {
|
||||||
if (empty($containerName)) {
|
if (empty($containerName)) {
|
||||||
array_push($this->nameStack, (string)$node->name);
|
$this->nameStack[] = (string)$node->name;
|
||||||
|
} else if ($node instanceof Node\Stmt\ClassMethod) {
|
||||||
|
$this->nameStack[] = $containerName . '::' . (string)$node->name;
|
||||||
|
} else {
|
||||||
|
$this->nameStack[] = $containerName . '\\' . (string)$node->name;
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
if ($node instanceof Node\Stmt\ClassMethod) {
|
$this->nameStack[] = $containerName;
|
||||||
array_push($this->nameStack, $containerName . '::' . (string)$node->name);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
array_push($this->nameStack, $containerName . '\\' . (string)$node->name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
array_push($this->nameStack, $containerName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$class = get_class($node);
|
$class = get_class($node);
|
||||||
|
|
|
@ -13,8 +13,8 @@ function findFilesRecursive(string $path, string $pattern): array {
|
||||||
$dir = new \RecursiveDirectoryIterator($path);
|
$dir = new \RecursiveDirectoryIterator($path);
|
||||||
$ite = new \RecursiveIteratorIterator($dir);
|
$ite = new \RecursiveIteratorIterator($dir);
|
||||||
$files = new \RegexIterator($ite, $pattern, \RegexIterator::GET_MATCH);
|
$files = new \RegexIterator($ite, $pattern, \RegexIterator::GET_MATCH);
|
||||||
$fileList = array();
|
$fileList = [];
|
||||||
foreach($files as $file) {
|
foreach ($files as $file) {
|
||||||
$fileList = array_merge($fileList, $file);
|
$fileList = array_merge($fileList, $file);
|
||||||
}
|
}
|
||||||
return $fileList;
|
return $fileList;
|
||||||
|
@ -29,5 +29,5 @@ function findFilesRecursive(string $path, string $pattern): array {
|
||||||
function pathToUri(string $filepath): string {
|
function pathToUri(string $filepath): string {
|
||||||
$filepath = trim(str_replace('\\', '/', $filepath), '/');
|
$filepath = trim(str_replace('\\', '/', $filepath), '/');
|
||||||
$filepath = implode('/', array_map('urlencode', explode('/', $filepath)));
|
$filepath = implode('/', array_map('urlencode', explode('/', $filepath)));
|
||||||
return 'file:///'.$filepath;
|
return 'file:///' . $filepath;
|
||||||
}
|
}
|
|
@ -21,8 +21,8 @@ class FileUriTest extends TestCase
|
||||||
$uri = \LanguageServer\pathToUri('/usr/local/bin');
|
$uri = \LanguageServer\pathToUri('/usr/local/bin');
|
||||||
$this->assertEquals('file:///usr/local/bin', $uri);
|
$this->assertEquals('file:///usr/local/bin', $uri);
|
||||||
|
|
||||||
$uri = \LanguageServer\pathToUri('a/b/c/');
|
$uri = \LanguageServer\pathToUri('a/b/c/test.txt');
|
||||||
$this->assertEquals('file:///a/b/c', $uri);
|
$this->assertEquals('file:///a/b/c/test.txt', $uri);
|
||||||
|
|
||||||
$uri = \LanguageServer\pathToUri('/d/e/f');
|
$uri = \LanguageServer\pathToUri('/d/e/f');
|
||||||
$this->assertEquals('file:///d/e/f', $uri);
|
$this->assertEquals('file:///d/e/f', $uri);
|
||||||
|
|
Loading…
Reference in New Issue