Adds some docs for how a formatter works#32072
Merged
Merged
Conversation
andrewbranch
approved these changes
Jun 24, 2019
|
|
||
| ### Where is this used? | ||
|
|
||
| The formatter is used mainly from the language service for formatting with an editor, but [services/textChanges.ts](/src/services/textChanges.ts) also uses this formatter when emitting code for quick fixes. |
Member
There was a problem hiding this comment.
AFAIK this is essentially “any language service operation that inserts or modifies code”
| ```ts | ||
| const nonFormattedText = `[js source code]`; | ||
| const sourceFile = createSourceFile("any file name", nonFormattedText, ScriptTarget.ESNext, /*setParentNodes*/ true, ScriptKind.JS); | ||
| const changes = formatting.formatDocument(sourceFile, formatContext); |
Member
There was a problem hiding this comment.
Not sure if this is realistic since everything happens internally within the language service itself 🤔
Contributor
Author
There was a problem hiding this comment.
yeah, might just kill the section
| As it recurses, `processNode` is called on the children setting the indentation is decided and passed | ||
| through into each of that node's children. | ||
|
|
||
| The meat of formatting decisions is made via `processPair`, the pair here being the current node and the previous node. `processPair` which mutates the formatting context to represent the current place in the scanner and requests a set of rules which can be applied to the items via `createRulesMap`. |
Member
There was a problem hiding this comment.
This paragraph and the next are probably the most important bits
Co-Authored-By: Andrew Branch <andrewbranch@users.noreply.github.com>
Co-Authored-By: Andrew Branch <andrewbranch@users.noreply.github.com>
Contributor
Author
|
Cool, thanks, will merge on green |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I've been reading the code on how the formatter works, and given an overall summary in the README docs
@andrewbranch - you were the most recent person to touch these, so I figure you might be a reasonable reviewer