Repository navigation
Gabritto/semicolons - #46832
Gabritto/semicolons#46832
Conversation
| const emptyStatement = factory.createExpressionStatement(factory.createIdentifier("")); | ||
| setSnippetElement(emptyStatement, { kind: SnippetKind.TabStop, order: 0 }); | ||
| body = factory.createBlock([emptyStatement], /* multiline */ true); | ||
| const emptyStmt = factory.createEmptyStatement(); |
There was a problem hiding this comment.
conceptually, it only makes sense for a tab stop snippet to be attached to a node that doesn't cause anything to be emitted. using an empty identifier, as I was before, was causing some troubles when setting positions for synthetic nodes, because we can't assume the identifier will be empty. an empty statement seemed more appropriate then.
There was a problem hiding this comment.
I can’t tell if you already got this, but an empty statement is only parsable when terminated by a semicolon, so in the reverse, it’s impossible to emit an empty statement without emitting a semicolon. Is the formatter removing this semicolon or did you somehow get this to emit without one?
There was a problem hiding this comment.
I hadn't thought of that, I think. The semicolon doesn't exist in this case because the empty statement is never emitted -- when we call emitTabStop, it doesn't emit the node (empty statement) the tab stop is attached to. Do you think that could be a problem?
There was a problem hiding this comment.
Got it. I don’t think it’s a problem, it’s just a little weird to think about.
There was a problem hiding this comment.
it's definitely weird. I tried to go for the least weird option :/
| ? "" : options.suffix); | ||
| } | ||
|
|
||
| function getFormatCodeSettingsForWriting({ options }: formatting.FormatContext, sourceFile: SourceFile): FormatCodeSettings { |
There was a problem hiding this comment.
moved to utilities
| /** | ||
| * Get format code settings for a code writing context (e.g. when formatting text changes or completions code). | ||
| */ | ||
| export function getFormatCodeSettingsForWriting({ options }: formatting.FormatContext, sourceFile: SourceFile): FormatCodeSettings { |
There was a problem hiding this comment.
moved here from textchanges
Fixes #46833.
We now have precedent for calling the formatter in completions. ✨