-
Notifications
You must be signed in to change notification settings - Fork 8
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
feat: facelift to console schema snippets #2804
Conversation
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.
LGTM. I just skimmed the React stuff though 😅
const line = lines[foundIdx] | ||
let out = line | ||
let subLineIdx = foundIdx + 1 | ||
while (subLineIdx < lines.length && lines[subLineIdx].startsWith(' ')) { |
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.
nit: does it make sense to do startsWith(' (\\w+)')
here as below instead of 4 spaces?
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.
Great question! So the behavior here is slightly different - basically, the (\\w+)
extracts the decl type from the line but ignores the start of the line, whereas this line is just checking the nesting depth from the start of the line.
|
||
// Scan backwards for comments | ||
subLineIdx = foundIdx - 1 | ||
while (subLineIdx >= 0 && lines[subLineIdx].startsWith(commentPrefix)) { |
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.
nice
<LinkToken token={splitToken[0]} containerRect={containerRect} /> | ||
(<UnderlyingType token={splitToken[1]} containerRect={containerRect} /> |
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.
do we need to check for splitToken.length
before these?
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.
Added. It should never happen, but if we add a new caller that doesn't check for it, then yeah the guard would definitely come in handy
export const specialChars = ['{', '}', '='] | ||
|
||
export function isFirstLineOfBlock(ll: string[], i: number): boolean { | ||
export function shouldAddLeadingSpace(ll: string[], i: number): boolean { |
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.
What are ll
s in these?
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.
renamed to lines
export function declFromModuleSchemaString(declName: string, schema: string) { | ||
const lines = schema.split('\n') |
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.
A lot of this function and file seems to be scanning the schema string to pull it back apart into decls, but we can get the raw schema as well and not have to deal with regexing on the string if that's easier.
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.
posting update from our slack discussion: we'll do that with the new endpoint: #2805
Fixes #2759