Skip to content
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

[Not Ready] [typespec-vscode] Add codefix for triple quate indent #5458

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

mzhongl524
Copy link
Member

Fix: #4609

Add codefix for triple-quote-indent warning ,and meanwhile add test case for it

@mzhongl524 mzhongl524 added the ide Issues for VS, VSCode, Monaco, etc. label Dec 27, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the compiler:core Issues for @typespec/compiler label Dec 27, 2024
@azure-sdk
Copy link
Collaborator

azure-sdk commented Dec 27, 2024

❌ There is undocummented changes. Run chronus add to add a changeset or click here.

The following packages have changes but are not documented.

  • @typespec/compiler
Show changes

@azure-sdk
Copy link
Collaborator

azure-sdk commented Dec 27, 2024

You can try these changes here

🛝 Playground 🌐 Website 📚 Next docs 🛝 VSCode Extension

const startPos = location.pos;
const endPos = location.end;
const offSet = 3;
const splitOrIndentStr = "\r\n";
Copy link
Contributor

Choose a reason for hiding this comment

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

the name is confusing, it's not a indent, right?

const splitStr = "\r\n";

const lines = splitLines(location.file.text, startPos, endPos);

Copy link
Contributor

Choose a reason for hiding this comment

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

handle the special case first, like 0 line, 1 line.

result.push(context.prependText({ ...location, pos: startPos }, splitStr + prefix));
}

if (lastLine.lineText.trim() === lines[lines.length - 1].lineText.trim()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

what's this for?

let indentDiff = lastLine.indent - minIndentLine.indent;
const prefix = " ".repeat(indentDiff);
// start triple-quote is not on a new line
if (firstLine.lineText.trim() !== "") {
Copy link
Contributor

Choose a reason for hiding this comment

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

you can save the check resolve instead of trim every time

lines.pop();
}

if (lines.length > 0 && firstLine.lineText.trim() === lines[0].lineText.trim()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

what's this for?

: lastLine.indent - minIndentLine.indent;
result.push(
context.prependText({ ...location, pos: endPos }, splitStr + " ".repeat(indentDiff)),
);
Copy link
Contributor

Choose a reason for hiding this comment

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

dont you need a '\n'?

const prefix = " ".repeat(indentDiff);
// start triple-quote is not on a new line
if (firstLine.lineText.trim() !== "") {
result.push(context.prependText({ ...location, pos: startPos }, splitStr + prefix));
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of adding fix for each line, can't we just have one fix for the whole string?


function getIndentNumbInLine(lineText: string): number {
let curStart = 0;
const curEnd = lineText.length;
Copy link
Contributor

Choose a reason for hiding this comment

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

usually end means a position, not lenght

});
}

function splitLines(
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason not use the existing one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:core Issues for @typespec/compiler ide Issues for VS, VSCode, Monaco, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can we have a codefix for triple-quote-indent diagnostic
3 participants