Skip to content

Fixed #5032: tsserver: Format on type broken #5033

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

Merged
merged 2 commits into from
Oct 14, 2015
Merged

Fixed #5032: tsserver: Format on type broken #5033

merged 2 commits into from
Oct 14, 2015

Conversation

dbaeumer
Copy link
Member

Fixes #5032

The Pull request changes the logic of the indentation correction code as follows:

  • computes the preferred indent using getIndentationAtPosition - this is spaces based
  • computes the current indent by scanning the line - this is normalized to spaces as well
  • if the two are different replace the current indent string with a new one. The newly generated indent string honors tabs and spaces

Although this is might replace a larger string then necessary it is easier to understand. And IMO it doesn't really matter if the edit replace n or m characters with m > n.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 30, 2015

👍

@@ -21,6 +21,21 @@ namespace ts.server {
return spaceCache[n];
}

export function generateIndentString(n: number, editorOptions: EditorOptions): string {
Copy link
Contributor

Choose a reason for hiding this comment

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

we already have similar function getIndentationString. Can it be used instead to avoid code duplication?

@vladima
Copy link
Contributor

vladima commented Sep 30, 2015

LGTM, assuming that notes about potential code reuse can be addressed

@mhegazy
Copy link
Contributor

mhegazy commented Sep 30, 2015

@dbaeumer can you also add a fourslash test?

@mhegazy
Copy link
Contributor

mhegazy commented Oct 2, 2015

@vladima spent some time yesterday trying to write a test for the original issue, and it does not seem possible given the current test infrastructure. the fourslash test behaves similar to VS, as it will not add indentation before calling format. so i would not bother about adding test for the original issue.

@mhegazy
Copy link
Contributor

mhegazy commented Oct 2, 2015

please add a test for preserving tabs though.

mhegazy added a commit that referenced this pull request Oct 14, 2015
 Fixed #5032: tsserver: Format on type broken
@mhegazy mhegazy merged commit 5234bf6 into master Oct 14, 2015
@mhegazy mhegazy deleted the dirkb/fix_5032 branch October 14, 2015 16:49
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants