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

Allow symbols to be escaped in DocText #3375

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

Conversation

rmhartog
Copy link

Related to #3374, this is an implementation of escaping characters in doc comments, such as the @ symbol.

@rmhartog
Copy link
Author

@microsoft-github-policy-service agree

@rmhartog rmhartog force-pushed the bug/escape-characters-in-docblock branch from bf80d93 to 2408c62 Compare May 16, 2024 12:20
Copy link
Member

@timotheeguerin timotheeguerin left a comment

Choose a reason for hiding this comment

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

@rmhartog thanks for the contribution, we'll discuss if that's something we want to add to the grammar of js doc. Seeing that it does that in TypeSCript I would assume it shouldn't be a problem. In the meantime if you want this to work you can also escape by wrapping the @ in backtick(markdown) playground

@timotheeguerin timotheeguerin added the compiler:core Issues for @typespec/compiler label May 16, 2024
@timotheeguerin
Copy link
Member

/azp run typespec - pr tools

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@azure-sdk
Copy link
Collaborator

azure-sdk commented May 17, 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

You can try these changes at https://cadlplayground.z22.web.core.windows.net/prs/3375/

Check the website changes at https://tspwebsitepr.z22.web.core.windows.net/prs/3375/

@@ -1036,6 +1042,14 @@ export function createScanner(
return text;
}

function getDocTextValue(): string {
if (tokenFlags & TokenFlags.Escaped) {
return unescapeString(tokenPosition, position);
Copy link
Member

Choose a reason for hiding this comment

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

We talked and I think we should have a different escape logic for the doc comment to be equivalent to JSDoc

Currently with your implementation it is erroring on invalid ecsape See this playground which is the logic we want for string but this would not be the same behavior as jsdoc(and also potentially a breaking change)

So we think if the backslash doesn't escape anything special it should just ignore and include it as is

/** Some \i escaped\*/

should result in Some \i escaped\ string value

Copy link
Author

Choose a reason for hiding this comment

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

I've added logic to ignore invalid escape sequences and return them verbatim, is this the direction you'd like to go?

Copy link
Author

Choose a reason for hiding this comment

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

I've inlined the unescapeString logic for this specific case and it now only handles \@ as an escape sequence. I'm unsure what other escape sequences would need to be supported within doctext, and also if this needs to be moved to a separate function. Curious to hear your thoughts.

Copy link
Member

Choose a reason for hiding this comment

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

I think this is nearly there, there is one edge case that is still not correct, if the escape is the last char

/** some \i \@escape \*/
model Foo {}

here i would espect the doc text to be

some \i @escape \

but is

some \i @escape \*

could you add those ignored escape to the test case as well

@rmhartog rmhartog force-pushed the bug/escape-characters-in-docblock branch from d5871e6 to 4306a71 Compare May 21, 2024 09:36
@rmhartog rmhartog force-pushed the bug/escape-characters-in-docblock branch from 4306a71 to c1e853c Compare May 22, 2024 07:50
@timotheeguerin
Copy link
Member

/azp run typespec - pr tools

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@microsoft microsoft deleted a comment from azure-pipelines bot May 23, 2024
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants