-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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#Provide a quickfix for non-exported types #37980
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.
Very good start! I would also like to see the case where the locals originate from a .d.ts
file. We shouldn't provide a quick fix in that case.
@DanielRosenwasser Feel free to review if you have time |
Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
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 agree that the message needs to change. I think fixing getAllCodeActions is difficult and probably less likely to be used than the individual fix anyway.
@Qiyu8 do you want to keep working on this? I think the main thing left to fix is the fix-all message. |
@sandersn Please feel free to merge right now ,write a custom getAllCodeActions handler is a little diffcult for me. |
@sandersn @DanielRosenwasser Is there anything I can do? |
Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
Sorry for the delay, I spent a lot of time in |
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.
This looks like it's getting very close to merging!
const statements = sourceFile.statements.filter(isExportDeclaration); | ||
for (const statement of statements) { | ||
if (statement.exportClause && isNamedExports(statement.exportClause)) { | ||
namedExport = statement; |
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.
namedExport = statement; | |
return statement; |
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 want to get the last export { }
and add the missing export there, so I can't return immediately.
return compareIdentifiers(s1.propertyName || s1.name, s2.propertyName || s2.name) || | ||
compareIdentifiers(s1.name, s2.name); |
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.
Why do you need to have the fallback here? Why can't this just be the following?
return compareIdentifiers(s1.propertyName || s1.name, s2.propertyName || s2.name) || | |
compareIdentifiers(s1.name, s2.name); | |
return compareIdentifiers(s1.propertyName || s1.name, s2.propertyName || s2.name); |
} | ||
if (isFunctionSymbol(localSymbol)) { | ||
const start = localSymbol.valueDeclaration.pos; | ||
changes.insertExportModifierAt(sourceFile, start ? start + 1 : 0); |
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 exactly is with the start + 1
? I don't understand.
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 want to add an export
identifier in front of non-exported type, you can see the codeFixImportNonExportedMember1.ts
, an export added before function bar()
, the start there is the position of line break, so need to +1 for start.
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.
The problem you are running into is more about using the pos
(a.k.a. the "full start") instead of the start after the trivia (what you'd get when you call getStart(sourceFile)
).
As far as I can tell, a test like
/**
* hello
*/
function bar() {
}
will likely end up with the export inside of the comment..
What happens when you just use insertExportModifier
instead of insertExportModifierAt
?
return; | ||
} | ||
if (isFunctionSymbol(localSymbol)) { | ||
const start = localSymbol.valueDeclaration.pos; |
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.
If you're suing pos
, that means you're including leading trivia.
this.insertExportModifierAt(sourceFile, node.getStart(sourceFile)); | ||
} | ||
|
||
public insertExportModifierAt(sourceFile: SourceFile, position: number): void { |
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 just don't quite know if you need this, but I don't understand the start + 1
thing yet.
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 want to add an export identifier in front of non-exported type, you can see the codeFixImportNonExportedMember1.ts, an export added before function bar(), the start there is the position of line break, so need to +1 for start.
@typescript-bot pack this |
Heya @DanielRosenwasser, I've started to run the tarball bundle task on this PR at 85d5b4a. You can monitor the build here. |
Hey @DanielRosenwasser, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running |
@DanielRosenwasser I think this PR is ready for merge, What else do I need to do? |
@typescript-bot pack this |
Heya @DanielRosenwasser, I've started to run the tarball bundle task on this PR at 85d5b4a. You can monitor the build here. |
#37980 (comment) is still something I am wondering about. I'm not seeing why the existing method didn't suffice here. |
Hey @DanielRosenwasser, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running There is also a playground for this build. |
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.
@Qiyu8 do you want to keep working on this? |
@sandersn Thanks for your caring, I think the only problem is to ensure the |
@Qiyu8 I haven't had good experience with comment trivia myself, so maybe you can look at similar codefixes or refactors and then try @DanielRosenwasser 's suggestions? |
@DanielRosenwasser How to get the
I want to add |
@Qiyu8 Sorry for dropping this for so long. I understand if you don't want to work on this anymore. To answer your latest question: |
This PR hasn't seen any activity for quite a while, so I'm going to close it to keep the number of open PRs manageable. Please let me know if you want to keep working on it and if you need more help to find the declaration of a function. |
Fixes #37440
if the locals originate from a .d.ts file, do nothing.
No export found in the file:
export