Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support document formatting #8 #10

Merged
merged 4 commits into from
Sep 6, 2016
Merged

Conversation

mniewrzal
Copy link
Contributor

@mniewrzal mniewrzal commented Sep 5, 2016

Closes #8

public function formatting(TextDocumentIdentifier $textDocument, FormattingOptions $options)
{
$nodes = $this->asts[$textDocument->uri];
if (empty($nodes)){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space missing before {

@felixfbecker
Copy link
Owner

}
$prettyPrinter = new PrettyPrinter();
$edit = new TextEdit();
$edit->range = new Range(new Position(0, 0), new Position(PHP_INT_MAX, PHP_INT_MAX));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbaeumer is it okay to do this to update the whole document?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felixfbecker yes and no. It is always best if an extension provides a minimal edit set since it will preserve the most markers attached to the text. We have code in place that runs a diff in the whole document gets replaced to compute some more minimal diff. However this might be suboptimal as well. So the more fine grain your edits are the better.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbaeumer Of course a minimal text edit is better, but the default implementation of PHPParser's PrettyPrinter will just spit out the new whole new content. We may customize the behavior later, but for now we just wanted to get the feature done. My question was only about wether it is okay to use a very big number (PHP_INT_MAX) to make it update the whole document (even though the EOF offset is much smaller) or if that is not protocol-conform and causes problems.

@felixfbecker
Copy link
Owner

felixfbecker commented Sep 6, 2016

Looking forward to using this while developing on the language server itself!
Always eat your own dog food 😄

@felixfbecker
Copy link
Owner

LGTM

@felixfbecker felixfbecker merged commit 6169998 into felixfbecker:master Sep 6, 2016
@tiansin tiansin mentioned this pull request Aug 22, 2017
@ghost ghost mentioned this pull request Apr 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants