-
-
Notifications
You must be signed in to change notification settings - Fork 89
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
Extract value refactoring #3251
Extract value refactoring #3251
Conversation
src/nl/hannahsten/texifyidea/refactoring/myextractfunction/LatexInPlaceVariableIntroducer.kt
Fixed
Show fixed
Hide fixed
src/nl/hannahsten/texifyidea/refactoring/myextractfunction/LatexExtractCommandHandler.kt
Fixed
Show fixed
Hide fixed
src/nl/hannahsten/texifyidea/refactoring/myextractfunction/LatexExtractCommandHandler.kt
Fixed
Show fixed
Hide fixed
src/nl/hannahsten/texifyidea/refactoring/myextractfunction/LatexExtractCommandHandler.kt
Fixed
Show fixed
Hide fixed
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 very promising!
- I really like how you reused OccurrencesChooser
- I would put the \newcommand simply in the preamble after the package inclusions, just like how we do it for inserting a
\usepackage
command,insertUsepackage()
- Don't forget to comment your code while you're writing it! Even if it's just rough code that doesn't work yet. it's much easier to do immediately than trying to remember afterwards what it's doing and why.
- Indeed there are some edge cases to do, but the general structure of the code is good I think. It's good that you asked for a quick review already.
I do not know how to navigate the PSI tree clearly. When attempting to refactor on
And the following are the parents that I get. Each line is a parent, newlines have been converted to
I really want a parent that is |
src/nl/hannahsten/texifyidea/refactoring/myextractfunction/LatexExtractCommandHandler.kt
Fixed
Show fixed
Hide fixed
I am very confused over why it breaks in this example: \documentclass[11pt]{article}
\begin{document}
$5.25 * 2.68291 = 450$
\begin{table}[ht!]
\begin{tabular}{| r |}
\hline
2.68291 \\
\hline
\end{tabular}
\end{table}
\begin{table}[ht!]
\begin{tabular}{| r |}
\hline
2.68<caret>291 \\
\hline
\end{tabular}
\end{table}
Some may wonder why 2.68291 is so special.
\end{document} and why removing the whitespace after the number magically makes it work. Yes it crashes because I throw the error, but that is because the tree is unexpectedly broken. |
src/nl/hannahsten/texifyidea/refactoring/myextractfunction/LatexExtractCommandHandler.kt
Fixed
Show fixed
Hide fixed
Ok, so I have one test that fails and I have no IDEA (haha so funny) why and another that fails because it doesnt do what I want yet ™️ |
@PHPirates can you disable checks on my draft pr's? They are a draft because they arent ready 🤯 |
I found that quotes are attached to a word token. This is disappointing because I think that if you select something inside quotes then the quotes should stay and the contents removed. See Also I fixed an issue regarding whitespace. If the edge of a selection was on whitespace, it would search in the wrong direction for the real boundary of your selection |
Regarding navigating the psi tree, I don't see the need to have individual sentences. I hope you should be able to go over all leaf psi elements (or only tokens?) and replace them if needed. Remember that replacing of psi elements is done by creating new psi elements from text using the psi helper (not sure if you already were doing this).
Good question, I'll have a look. |
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 looked at the quotes test, and not sure what is currently happening but I would think this is what you need to do:
- Find the psi element under the caret, in this case the whole sentence
- Find the actual selected text
- Create the \newcommand
- Take the sentence text, then string replace the text that was selected by the command, then create a psi element from it and replace it
src/nl/hannahsten/texifyidea/refactoring/myextractfunction/LatexExtractCommandHandler.kt
Outdated
Show resolved
Hide resolved
src/nl/hannahsten/texifyidea/refactoring/myextractfunction/LatexExtractCommandHandler.kt
Outdated
Show resolved
Hide resolved
src/nl/hannahsten/texifyidea/refactoring/myextractfunction/LatexExtractCommandHandler.kt
Outdated
Show resolved
Hide resolved
src/nl/hannahsten/texifyidea/refactoring/myextractfunction/LatexExtractCommandHandler.kt
Outdated
Show resolved
Hide resolved
Everything is broken by last commit, but it is the first step before we are able to extract something that isnt represented by something in the PSI tree like a text line or the inside of quotes or something else not covered by the lexer. |
Fixes #3255 |
src/nl/hannahsten/texifyidea/refactoring/introduceCommand/LatexExtractCommandHandler.kt
Outdated
Show resolved
Hide resolved
src/nl/hannahsten/texifyidea/refactoring/introduceCommand/LatexExtractCommandHandler.kt
Outdated
Show resolved
Hide resolved
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 think it would be good to clean up the code first, before you decide to add more features. That would also allow me to review functionality, because currently it's just raising a lot of exceptions and I don't know which cases it should work and which cases it shouldn't.
Would it be possible to have like this small popup 'extract value is not supported here' or some other sort of user feedback in the cases where we don't support it yet? That would be really helpful, also in reviewing.
I'm talking about exceptions like these:
java.lang.IllegalStateException: @NotNull method com/intellij/psi/impl/PsiElementBase.notNullChild must not return null
at com.intellij.psi.impl.PsiElementBase.$$$reportNull$$$0(PsiElementBase.java)
at com.intellij.psi.impl.PsiElementBase.notNullChild(PsiElementBase.java:282)
at nl.hannahsten.texifyidea.psi.impl.LatexCommandsImpl.getCommandToken(LatexCommandsImpl.java:44)
at nl.hannahsten.texifyidea.psi.impl.LatexCommandsImplMixin.getName(LatexCommandsImplMixin.kt:63)
at nl.hannahsten.texifyidea.reference.CommandDefinitionReference.multiResolve(CommandDefinitionReference.kt:31)
at nl.hannahsten.texifyidea.psi.impl.LatexCommandsImplMixin.getReferences(LatexCommandsImplMixin.kt:106)
at com.intellij.psi.impl.SharedPsiElementImplUtil.addReferences(SharedPsiElementImplUtil.java:58)
at
Can you add tests for where you make the exception cuz I am not getting those, probably because im not trying hard enough admittedly |
By coercion of test cases or actual fixes
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 nice! Of course there's always more edge cases, but I think the most important cases are covered.
Now I think it's a matter of cleaning up the code, adding comments, etc. so we can merge it!
I am mostly done, let me know what else youd like @PHPirates |
That would be great! No I think that's all, code quality looks good for the rest, nice job |
Fix #3243
Currently trying to implement at minimum a basic 'extract duplicated code' feature (not the inspection)
TODO:
findOccurrences
visit all inclusions in this file, and to go upstream via inclusions to this fileNow I really want
introduceParameter
for a custom command. Would that be extremely hard?