Skip to content

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

Merged
mhegazy merged 2 commits into
masterfrom
dirkb/fix_5032
Oct 14, 2015
Merged

Fixed #5032: tsserver: Format on type broken #5033
mhegazy merged 2 commits into
masterfrom
dirkb/fix_5032

Conversation

@dbaeumer

Copy link
Copy Markdown
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

mhegazy commented Sep 30, 2015

Copy link
Copy Markdown
Contributor

👍

Comment thread src/server/session.ts

Copy link
Copy Markdown
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

vladima commented Sep 30, 2015

Copy link
Copy Markdown
Contributor

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

@mhegazy

mhegazy commented Sep 30, 2015

Copy link
Copy Markdown
Contributor

@dbaeumer can you also add a fourslash test?

@mhegazy

mhegazy commented Oct 2, 2015

Copy link
Copy Markdown
Contributor

@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

mhegazy commented Oct 2, 2015

Copy link
Copy Markdown
Contributor

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