diff --git a/README.md b/README.md index 90c66cbf..8e7117c7 100644 --- a/README.md +++ b/README.md @@ -42,9 +42,6 @@ For Parameters, it will return the `@param` tag. The query is matched case-insensitively against the fully qualified name of the symbol. Non-Standard: An empty query will return _all_ symbols found in the workspace. -### [Document Formatting](https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#document-formatting-request) -![Document Formatting demo](images/formatDocument.gif) - ### Error reporting through [Publish Diagnostics](https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#publishdiagnostics-notification) ![Error reporting demo](images/publishDiagnostics.png) diff --git a/composer.json b/composer.json index ceb357dd..a21535bb 100644 --- a/composer.json +++ b/composer.json @@ -30,12 +30,12 @@ "phpdocumentor/reflection-docblock": "^4.0.0", "sabre/event": "^5.0", "sabre/uri": "^2.0", - "squizlabs/php_codesniffer": "3.0.0RC3", "webmozart/glob": "^4.1", "webmozart/path-util": "^2.3" }, "require-dev": { - "phpunit/phpunit": "^6.3" + "phpunit/phpunit": "^6.3", + "squizlabs/php_codesniffer": "^3.1" }, "autoload": { "psr-4": { diff --git a/fixtures/format.php b/fixtures/format.php deleted file mode 100644 index bd356404..00000000 --- a/fixtures/format.php +++ /dev/null @@ -1,20 +0,0 @@ -standards = self::findConfiguration($path); - - // Autoload class to set up a bunch of PHP_CodeSniffer-specific token type constants - spl_autoload_call(Tokens::class); - - $file = new DummyFile($content, new Ruleset($config), $config); - $file->process(); - $fixed = $file->fixer->fixFile(); - if (!$fixed && $file->getErrorCount() > 0) { - throw new Exception('Unable to format file'); - } - - $new = $file->fixer->getContents(); - if ($content === $new) { - return []; - } - return [new TextEdit(new Range(new Position(0, 0), self::calculateEndPosition($content)), $new)]; - } - - /** - * Calculate position of last character. - * - * @param string $content document as string - * - * @return \LanguageServer\Protocol\Position - */ - private static function calculateEndPosition(string $content): Position - { - $lines = explode("\n", $content); - return new Position(count($lines) - 1, strlen(end($lines))); - } - - /** - * Search for PHP_CodeSniffer configuration file at given directory or its parents. - * If no configuration found then PSR2 standard is loaded by default. - * - * @param string $path path to file or directory - * @return string[] - */ - private static function findConfiguration(string $path) - { - if (is_dir($path)) { - $currentDir = $path; - } else { - $currentDir = dirname($path); - } - do { - $default = $currentDir . DIRECTORY_SEPARATOR . 'phpcs.xml'; - if (is_file($default)) { - return [$default]; - } - - $default = $currentDir . DIRECTORY_SEPARATOR . 'phpcs.xml.dist'; - if (is_file($default)) { - return [$default]; - } - - $lastDir = $currentDir; - $currentDir = dirname($currentDir); - } while ($currentDir !== '.' && $currentDir !== $lastDir); - - $standard = Config::getConfigData('default_standard') ?? 'PSR2'; - return explode(',', $standard); - } -} diff --git a/src/LanguageServer.php b/src/LanguageServer.php index 118dd937..73560f4f 100644 --- a/src/LanguageServer.php +++ b/src/LanguageServer.php @@ -265,8 +265,6 @@ public function initialize(ClientCapabilities $capabilities, string $rootPath = $serverCapabilities->documentSymbolProvider = true; // Support "Find all symbols in workspace" $serverCapabilities->workspaceSymbolProvider = true; - // Support "Format Code" - $serverCapabilities->documentFormattingProvider = true; // Support "Go to definition" $serverCapabilities->definitionProvider = true; // Support "Find all references" diff --git a/src/PhpDocument.php b/src/PhpDocument.php index ff3cf8b5..0ac84210 100644 --- a/src/PhpDocument.php +++ b/src/PhpDocument.php @@ -166,19 +166,6 @@ public function updateContent(string $content) $this->sourceFileNode = $treeAnalyzer->getSourceFileNode(); } - /** - * Returns array of TextEdit changes to format this document. - * - * @return \LanguageServer\Protocol\TextEdit[] - */ - public function getFormattedText() - { - if (empty($this->getContent())) { - return []; - } - return Formatter::format($this->getContent(), $this->uri); - } - /** * Returns this document's text content. * diff --git a/src/Server/TextDocument.php b/src/Server/TextDocument.php index 2bcda2c0..58e7074a 100644 --- a/src/Server/TextDocument.php +++ b/src/Server/TextDocument.php @@ -159,20 +159,6 @@ public function didClose(TextDocumentIdentifier $textDocument) $this->documentLoader->close($textDocument->uri); } - /** - * The document formatting request is sent from the server to the client to format a whole document. - * - * @param TextDocumentIdentifier $textDocument The document to format - * @param FormattingOptions $options The format options - * @return Promise - */ - public function formatting(TextDocumentIdentifier $textDocument, FormattingOptions $options) - { - return $this->documentLoader->getOrLoad($textDocument->uri)->then(function (PhpDocument $document) { - return $document->getFormattedText(); - }); - } - /** * The references request is sent from the client to the server to resolve project-wide references for the symbol * denoted by the given text document position. diff --git a/tests/FormatterTest.php b/tests/FormatterTest.php deleted file mode 100644 index a46f2ec7..00000000 --- a/tests/FormatterTest.php +++ /dev/null @@ -1,28 +0,0 @@ -assertSame($output, $edits[0]->newText); - } - - public function testFormatNoChange() - { - $expected = file_get_contents(__DIR__ . '/../fixtures/format_expected.php'); - - $edits = Formatter::format($expected, 'file:///whatever'); - $this->assertSame([], $edits); - } -} diff --git a/tests/LanguageServerTest.php b/tests/LanguageServerTest.php index 5d034517..5d581729 100644 --- a/tests/LanguageServerTest.php +++ b/tests/LanguageServerTest.php @@ -34,7 +34,6 @@ public function testInitialize() $serverCapabilities->textDocumentSync = TextDocumentSyncKind::FULL; $serverCapabilities->documentSymbolProvider = true; $serverCapabilities->workspaceSymbolProvider = true; - $serverCapabilities->documentFormattingProvider = true; $serverCapabilities->definitionProvider = true; $serverCapabilities->referencesProvider = true; $serverCapabilities->hoverProvider = true; diff --git a/tests/Server/TextDocument/FormattingTest.php b/tests/Server/TextDocument/FormattingTest.php deleted file mode 100644 index 18448918..00000000 --- a/tests/Server/TextDocument/FormattingTest.php +++ /dev/null @@ -1,50 +0,0 @@ -uri = $uri; - $textDocumentItem->languageId = 'php'; - $textDocumentItem->version = 1; - $textDocumentItem->text = file_get_contents($path); - $textDocument->didOpen($textDocumentItem); - - // how code should look after formatting - $expected = file_get_contents(__DIR__ . '/../../../fixtures/format_expected.php'); - // Request formatting - $result = $textDocument->formatting(new TextDocumentIdentifier($uri), new FormattingOptions())->wait(); - $this->assertEquals([new TextEdit(new Range(new Position(0, 0), new Position(20, 0)), $expected)], $result); - } -}