Skip to content

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

Merged
merged 8 commits into from
Jan 4, 2022
Merged

Gabritto/semicolons #46832

merged 8 commits into from
Jan 4, 2022

Conversation

gabritto
Copy link
Member

@gabritto gabritto commented Nov 17, 2021

Fixes #46833.

We now have precedent for calling the formatter in completions. ✨

const emptyStatement = factory.createExpressionStatement(factory.createIdentifier(""));
setSnippetElement(emptyStatement, { kind: SnippetKind.TabStop, order: 0 });
body = factory.createBlock([emptyStatement], /* multiline */ true);
const emptyStmt = factory.createEmptyStatement();
Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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 {
Copy link
Member Author

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 {
Copy link
Member Author

Choose a reason for hiding this comment

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

moved here from textchanges

@gabritto gabritto merged commit 404a7d6 into main Jan 4, 2022
@gabritto gabritto deleted the gabritto/semicolons branch January 4, 2022 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Class member snippet completions always have semicolon
4 participants