Skip to content

Commit f00fd1b

Browse files
authored
fix(formatting): drop PHP CodeSniffer (#504)
At this point there are countless issues about the formatting done by CodeSniffer. It plain out doesn't work in many cases, overrides format options that are contributed by other extensions in VS Code and does not reuse any of our AST parsing. For that reason, I am starting to think there is no reason to keep it in here until we have proper pretty-printing support from https://github.com/Microsoft/tolerant-php-parser that actually reuses our ASTs and can work while editing. For people who want to use CodeSniffer to format their code, there could be a standalone CodeSniffer language server (like there is a TSLint language server and ESLint language server). As said, we don't reuse our state anyway. BREAKING CHANGE: removes formatting support closes #501 closes #474 closes #473 closes #468 closes #450 closes #445 closes #443 closes #423 closes #343 closes #296 closes #293 closes #499 closes #471
1 parent e9fc97d commit f00fd1b

12 files changed

+2
-259
lines changed

README.md

-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ For Parameters, it will return the `@param` tag.
4242
The query is matched case-insensitively against the fully qualified name of the symbol.
4343
Non-Standard: An empty query will return _all_ symbols found in the workspace.
4444

45-
### [Document Formatting](https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#document-formatting-request)
46-
![Document Formatting demo](images/formatDocument.gif)
47-
4845
### Error reporting through [Publish Diagnostics](https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#publishdiagnostics-notification)
4946
![Error reporting demo](images/publishDiagnostics.png)
5047

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
"phpdocumentor/reflection-docblock": "^4.0.0",
3131
"sabre/event": "^5.0",
3232
"sabre/uri": "^2.0",
33-
"squizlabs/php_codesniffer": "3.0.0RC3",
3433
"webmozart/glob": "^4.1",
3534
"webmozart/path-util": "^2.3"
3635
},
3736
"require-dev": {
38-
"phpunit/phpunit": "^6.3"
37+
"phpunit/phpunit": "^6.3",
38+
"squizlabs/php_codesniffer": "^3.1"
3939
},
4040
"autoload": {
4141
"psr-4": {

fixtures/format.php

-20
This file was deleted.

fixtures/format_expected.php

-19
This file was deleted.

images/formatDocument.gif

-51 KB
Binary file not shown.

src/Formatter.php

-107
This file was deleted.

src/LanguageServer.php

-2
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,6 @@ public function initialize(ClientCapabilities $capabilities, string $rootPath =
265265
$serverCapabilities->documentSymbolProvider = true;
266266
// Support "Find all symbols in workspace"
267267
$serverCapabilities->workspaceSymbolProvider = true;
268-
// Support "Format Code"
269-
$serverCapabilities->documentFormattingProvider = true;
270268
// Support "Go to definition"
271269
$serverCapabilities->definitionProvider = true;
272270
// Support "Find all references"

src/PhpDocument.php

-13
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,6 @@ public function updateContent(string $content)
166166
$this->sourceFileNode = $treeAnalyzer->getSourceFileNode();
167167
}
168168

169-
/**
170-
* Returns array of TextEdit changes to format this document.
171-
*
172-
* @return \LanguageServer\Protocol\TextEdit[]
173-
*/
174-
public function getFormattedText()
175-
{
176-
if (empty($this->getContent())) {
177-
return [];
178-
}
179-
return Formatter::format($this->getContent(), $this->uri);
180-
}
181-
182169
/**
183170
* Returns this document's text content.
184171
*

src/Server/TextDocument.php

-14
Original file line numberDiff line numberDiff line change
@@ -159,20 +159,6 @@ public function didClose(TextDocumentIdentifier $textDocument)
159159
$this->documentLoader->close($textDocument->uri);
160160
}
161161

162-
/**
163-
* The document formatting request is sent from the server to the client to format a whole document.
164-
*
165-
* @param TextDocumentIdentifier $textDocument The document to format
166-
* @param FormattingOptions $options The format options
167-
* @return Promise <TextEdit[]>
168-
*/
169-
public function formatting(TextDocumentIdentifier $textDocument, FormattingOptions $options)
170-
{
171-
return $this->documentLoader->getOrLoad($textDocument->uri)->then(function (PhpDocument $document) {
172-
return $document->getFormattedText();
173-
});
174-
}
175-
176162
/**
177163
* The references request is sent from the client to the server to resolve project-wide references for the symbol
178164
* denoted by the given text document position.

tests/FormatterTest.php

-28
This file was deleted.

tests/LanguageServerTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public function testInitialize()
3434
$serverCapabilities->textDocumentSync = TextDocumentSyncKind::FULL;
3535
$serverCapabilities->documentSymbolProvider = true;
3636
$serverCapabilities->workspaceSymbolProvider = true;
37-
$serverCapabilities->documentFormattingProvider = true;
3837
$serverCapabilities->definitionProvider = true;
3938
$serverCapabilities->referencesProvider = true;
4039
$serverCapabilities->hoverProvider = true;

tests/Server/TextDocument/FormattingTest.php

-50
This file was deleted.

0 commit comments

Comments
 (0)