-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Gabritto/semicolons #46832
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's definitely weird. I tried to go for the least weird option :/
@@ -1052,15 +1052,6 @@ namespace ts.textChanges { | |||
? "" : options.suffix); | |||
} | |||
|
|||
function getFormatCodeSettingsForWriting({ options }: formatting.FormatContext, sourceFile: SourceFile): FormatCodeSettings { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved here from textchanges
Fixes #46833.
We now have precedent for calling the formatter in completions. ✨