Automatic fixes
parent
c8244f138a
commit
5285aea1f4
|
@ -4,8 +4,8 @@ declare(strict_types = 1);
|
||||||
namespace LanguageServer;
|
namespace LanguageServer;
|
||||||
|
|
||||||
use LanguageServer\Protocol\ {
|
use LanguageServer\Protocol\ {
|
||||||
TextEdit,
|
TextEdit,
|
||||||
Range,
|
Range,
|
||||||
Position
|
Position
|
||||||
};
|
};
|
||||||
use PHP_CodeSniffer;
|
use PHP_CodeSniffer;
|
||||||
|
@ -42,9 +42,9 @@ abstract class Formatter
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate position of last character.
|
* Calculate position of last character.
|
||||||
*
|
*
|
||||||
* @param string $content document as string
|
* @param string $content document as string
|
||||||
*
|
*
|
||||||
* @return \LanguageServer\Protocol\Position
|
* @return \LanguageServer\Protocol\Position
|
||||||
*/
|
*/
|
||||||
private static function calculateEndPosition(string $content): Position
|
private static function calculateEndPosition(string $content): Position
|
||||||
|
@ -54,10 +54,10 @@ abstract class Formatter
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search for PHP_CodeSniffer configuration file at given directory or its parents.
|
* Search for PHP_CodeSniffer configuration file at given directory or its parents.
|
||||||
* If no configuration found then PSR2 standard is loaded by default.
|
* If no configuration found then PSR2 standard is loaded by default.
|
||||||
*
|
*
|
||||||
* @param string $path path to file or directory
|
* @param string $path path to file or directory
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
private static function findConfiguration(string $path)
|
private static function findConfiguration(string $path)
|
||||||
|
@ -85,5 +85,4 @@ abstract class Formatter
|
||||||
$standard = PHP_CodeSniffer::getConfigData('default_standard') ?? 'PSR2';
|
$standard = PHP_CodeSniffer::getConfigData('default_standard') ?? 'PSR2';
|
||||||
return explode(',', $standard);
|
return explode(',', $standard);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,7 +163,7 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
|
||||||
$startTime = microtime(true);
|
$startTime = microtime(true);
|
||||||
$fileNum = 0;
|
$fileNum = 0;
|
||||||
|
|
||||||
$processFile = function() use (&$fileList, &$fileNum, &$processFile, $numTotalFiles, $startTime) {
|
$processFile = function () use (&$fileList, &$fileNum, &$processFile, $numTotalFiles, $startTime) {
|
||||||
if ($fileNum < $numTotalFiles) {
|
if ($fileNum < $numTotalFiles) {
|
||||||
$file = $fileList[$fileNum];
|
$file = $fileList[$fileNum];
|
||||||
$uri = pathToUri($file);
|
$uri = pathToUri($file);
|
||||||
|
|
|
@ -178,7 +178,8 @@ class Project
|
||||||
* @param string $fqn The fully qualified name of the symbol
|
* @param string $fqn The fully qualified name of the symbol
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function removeSymbol(string $fqn) {
|
public function removeSymbol(string $fqn)
|
||||||
|
{
|
||||||
unset($this->symbols[$fqn]);
|
unset($this->symbols[$fqn]);
|
||||||
unset($this->references[$fqn]);
|
unset($this->references[$fqn]);
|
||||||
}
|
}
|
||||||
|
@ -207,7 +208,8 @@ class Project
|
||||||
* @param string $uri The URI
|
* @param string $uri The URI
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function removeReferenceUri(string $fqn, string $uri) {
|
public function removeReferenceUri(string $fqn, string $uri)
|
||||||
|
{
|
||||||
if (!isset($this->references[$fqn])) {
|
if (!isset($this->references[$fqn])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,8 @@ namespace LanguageServer\Protocol;
|
||||||
/**
|
/**
|
||||||
* The kind of a completion entry.
|
* The kind of a completion entry.
|
||||||
*/
|
*/
|
||||||
abstract class CompletionItemKind {
|
abstract class CompletionItemKind
|
||||||
|
{
|
||||||
const TEXT = 1;
|
const TEXT = 1;
|
||||||
const METHOD = 2;
|
const METHOD = 2;
|
||||||
const FUNCTION = 3;
|
const FUNCTION = 3;
|
||||||
|
|
|
@ -4,10 +4,10 @@ namespace LanguageServer\Protocol;
|
||||||
|
|
||||||
class ReferenceContext
|
class ReferenceContext
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Include the declaration of the current symbol.
|
* Include the declaration of the current symbol.
|
||||||
*
|
*
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
public $includeDeclaration;
|
public $includeDeclaration;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ class ProtocolStreamReader implements ProtocolReader
|
||||||
public function __construct($input)
|
public function __construct($input)
|
||||||
{
|
{
|
||||||
$this->input = $input;
|
$this->input = $input;
|
||||||
Loop\addReadStream($this->input, function() {
|
Loop\addReadStream($this->input, function () {
|
||||||
if (feof($this->input)) {
|
if (feof($this->input)) {
|
||||||
throw new RuntimeException('Stream is closed');
|
throw new RuntimeException('Stream is closed');
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,8 @@ use InvalidArgumentException;
|
||||||
* @param string $pattern
|
* @param string $pattern
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function findFilesRecursive(string $path, string $pattern): array {
|
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);
|
||||||
|
@ -29,7 +30,8 @@ function findFilesRecursive(string $path, string $pattern): array {
|
||||||
* @param string $filepath
|
* @param string $filepath
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function pathToUri(string $filepath): string {
|
function pathToUri(string $filepath): string
|
||||||
|
{
|
||||||
$filepath = trim(str_replace('\\', '/', $filepath), '/');
|
$filepath = trim(str_replace('\\', '/', $filepath), '/');
|
||||||
$parts = explode('/', $filepath);
|
$parts = explode('/', $filepath);
|
||||||
// Don't %-encode the colon after a Windows drive letter
|
// Don't %-encode the colon after a Windows drive letter
|
||||||
|
|
|
@ -36,4 +36,3 @@ class MockProtocolStream implements ProtocolReader, ProtocolWriter
|
||||||
$this->listener = $listener;
|
$this->listener = $listener;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,13 +9,15 @@ use function LanguageServer\pathToUri;
|
||||||
|
|
||||||
class GlobalTest extends ServerTestCase
|
class GlobalTest extends ServerTestCase
|
||||||
{
|
{
|
||||||
public function testDefinitionFileBeginning() {
|
public function testDefinitionFileBeginning()
|
||||||
|
{
|
||||||
// |<?php
|
// |<?php
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier(pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'))), new Position(0, 0));
|
$result = $this->textDocument->definition(new TextDocumentIdentifier(pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'))), new Position(0, 0));
|
||||||
$this->assertEquals([], $result);
|
$this->assertEquals([], $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDefinitionEmptyResult() {
|
public function testDefinitionEmptyResult()
|
||||||
|
{
|
||||||
// namespace keyword
|
// namespace keyword
|
||||||
$result = $this->textDocument->definition(new TextDocumentIdentifier(pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'))), new Position(2, 4));
|
$result = $this->textDocument->definition(new TextDocumentIdentifier(pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'))), new Position(2, 4));
|
||||||
$this->assertEquals([], $result);
|
$this->assertEquals([], $result);
|
||||||
|
|
|
@ -36,7 +36,8 @@ class ParseErrorsTest extends TestCase
|
||||||
$this->textDocument = new Server\TextDocument($project, $client);
|
$this->textDocument = new Server\TextDocument($project, $client);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function openFile($file) {
|
private function openFile($file)
|
||||||
|
{
|
||||||
$textDocumentItem = new TextDocumentItem();
|
$textDocumentItem = new TextDocumentItem();
|
||||||
$textDocumentItem->uri = 'whatever';
|
$textDocumentItem->uri = 'whatever';
|
||||||
$textDocumentItem->languageId = 'php';
|
$textDocumentItem->languageId = 'php';
|
||||||
|
|
Loading…
Reference in New Issue