mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
spell checker: do not extract misspelled word from problem description in onTheFly mode - store exact string instead
This commit is contained in:
+7
-19
@@ -23,9 +23,6 @@ import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
|
||||
import com.intellij.lang.*;
|
||||
import com.intellij.lang.refactoring.NamesValidator;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.fileTypes.PlainTextLanguage;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
@@ -41,7 +38,6 @@ import com.intellij.spellchecker.tokenizer.TokenConsumer;
|
||||
import com.intellij.spellchecker.tokenizer.Tokenizer;
|
||||
import com.intellij.spellchecker.util.SpellCheckerBundle;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.containers.hash.HashMap;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -49,7 +45,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@@ -147,11 +142,11 @@ public class SpellCheckingInspection extends LocalInspectionTool {
|
||||
holder.registerProblem(problemDescriptor);
|
||||
}
|
||||
|
||||
private static void addRegularDescriptor(PsiElement element, int offset, @NotNull TextRange textRange, @NotNull ProblemsHolder holder,
|
||||
boolean useRename) {
|
||||
private static void addRegularDescriptor(PsiElement element, int offset, @NotNull TextRange textRange, @NotNull ProblemsHolder holder,
|
||||
boolean useRename, String wordWithTypo) {
|
||||
SpellCheckerQuickFix[] fixes = new SpellCheckerQuickFix[]{
|
||||
(useRename ? new RenameTo() : new ChangeTo()),
|
||||
new AcceptWordAsCorrect()
|
||||
(useRename ? new RenameTo(wordWithTypo) : new ChangeTo(wordWithTypo)),
|
||||
new AcceptWordAsCorrect(wordWithTypo)
|
||||
};
|
||||
|
||||
final ProblemDescriptor problemDescriptor = createProblemDescriptor(element, offset, textRange, holder, fixes, true);
|
||||
@@ -165,15 +160,8 @@ public class SpellCheckingInspection extends LocalInspectionTool {
|
||||
final TextRange highlightRange = TextRange.from(offset + textRange.getStartOffset(), textRange.getLength());
|
||||
assert highlightRange.getStartOffset()>=0;
|
||||
|
||||
final ProblemDescriptor problemDescriptor = holder.getManager()
|
||||
.createProblemDescriptor(element, highlightRange, description, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, holder.isOnTheFly(),
|
||||
fixes);
|
||||
if(onTheFly) {
|
||||
for (SpellCheckerQuickFix fix : fixes) {
|
||||
fix.setDescriptor(problemDescriptor);
|
||||
}
|
||||
}
|
||||
return problemDescriptor;
|
||||
return holder.getManager()
|
||||
.createProblemDescriptor(element, highlightRange, description, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, holder.isOnTheFly(), fixes);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"PublicField"})
|
||||
@@ -254,7 +242,7 @@ public class SpellCheckingInspection extends LocalInspectionTool {
|
||||
addBatchDescriptor(myElement, myOffset, textRange, myHolder);
|
||||
}
|
||||
else {
|
||||
addRegularDescriptor(myElement, myOffset, textRange, myHolder, myUseRename);
|
||||
addRegularDescriptor(myElement, myOffset, textRange, myHolder, myUseRename, word);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-11
@@ -16,7 +16,6 @@
|
||||
package com.intellij.spellchecker.quickfixes;
|
||||
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.codeInspection.ui.ProblemDescriptionNode;
|
||||
import com.intellij.openapi.actionSystem.Anchor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.spellchecker.SpellCheckerManager;
|
||||
@@ -27,16 +26,18 @@ import javax.swing.*;
|
||||
|
||||
|
||||
public class AcceptWordAsCorrect implements SpellCheckerQuickFix {
|
||||
private ProblemDescriptor myProblemDescriptor;
|
||||
private String myWord;
|
||||
|
||||
public AcceptWordAsCorrect(String word) {
|
||||
myWord = word;
|
||||
}
|
||||
|
||||
public AcceptWordAsCorrect() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return myProblemDescriptor!=null ? SpellCheckerBundle.message("add.0.to.dictionary", ProblemDescriptionNode.extractHighlightedText(myProblemDescriptor, myProblemDescriptor.getPsiElement()))
|
||||
: SpellCheckerBundle.message("add.to.dictionary")
|
||||
;
|
||||
return myWord != null ? SpellCheckerBundle.message("add.0.to.dictionary", myWord) : SpellCheckerBundle.message("add.to.dictionary");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -51,15 +52,10 @@ public class AcceptWordAsCorrect implements SpellCheckerQuickFix {
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
SpellCheckerManager spellCheckerManager = SpellCheckerManager.getInstance(project);
|
||||
final String w = ProblemDescriptionNode.extractHighlightedText(descriptor, descriptor.getPsiElement());
|
||||
spellCheckerManager.acceptWordAsCorrect(w, project);
|
||||
spellCheckerManager.acceptWordAsCorrect(myWord, project);
|
||||
}
|
||||
|
||||
public Icon getIcon(int flags) {
|
||||
return new ImageIcon(ShowSuggestions.class.getResource("spellcheck.png"));
|
||||
}
|
||||
|
||||
public void setDescriptor(ProblemDescriptor problemDescriptor) {
|
||||
myProblemDescriptor = problemDescriptor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,8 +35,8 @@ import java.util.List;
|
||||
|
||||
public class ChangeTo extends ShowSuggestions implements SpellCheckerQuickFix {
|
||||
|
||||
public ChangeTo() {
|
||||
super();
|
||||
public ChangeTo(String wordWithTypo) {
|
||||
super(wordWithTypo);
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ public class ChangeTo extends ShowSuggestions implements SpellCheckerQuickFix {
|
||||
}
|
||||
|
||||
List<LookupElement> lookupItems = new ArrayList<LookupElement>();
|
||||
for (String variant : getSuggestions()) {
|
||||
for (String variant : getSuggestions(project)) {
|
||||
lookupItems.add(LookupElementBuilder.create(variant));
|
||||
}
|
||||
LookupElement[] items = new LookupElement[lookupItems.size()];
|
||||
|
||||
@@ -40,8 +40,8 @@ import javax.swing.*;
|
||||
|
||||
public class RenameTo extends ShowSuggestions implements SpellCheckerQuickFix {
|
||||
|
||||
public RenameTo() {
|
||||
super();
|
||||
public RenameTo(String wordWithTypo) {
|
||||
super(wordWithTypo);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -16,11 +16,8 @@
|
||||
package com.intellij.spellchecker.quickfixes;
|
||||
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.codeInspection.ui.ProblemDescriptionNode;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Iconable;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.spellchecker.SpellCheckerManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -32,31 +29,23 @@ public abstract class ShowSuggestions implements LocalQuickFix, Iconable {
|
||||
|
||||
private List<String> suggestions;
|
||||
private boolean processed;
|
||||
protected ProblemDescriptor myProblemDescriptor;
|
||||
private final String myWordWithTypo;
|
||||
|
||||
|
||||
public ShowSuggestions() {
|
||||
public ShowSuggestions(String wordWithTypo) {
|
||||
myWordWithTypo = wordWithTypo;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<String> getSuggestions(){
|
||||
public List<String> getSuggestions(Project project){
|
||||
if (!processed){
|
||||
calculateSuggestions();
|
||||
processed=true;
|
||||
suggestions = SpellCheckerManager.getInstance(project).getSuggestions(myWordWithTypo);
|
||||
processed = true;
|
||||
}
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
private void calculateSuggestions(){
|
||||
SpellCheckerManager manager = SpellCheckerManager.getInstance(myProblemDescriptor.getPsiElement().getProject());
|
||||
suggestions = manager.getSuggestions(ProblemDescriptionNode.extractHighlightedText(myProblemDescriptor, myProblemDescriptor.getPsiElement()));
|
||||
}
|
||||
|
||||
public Icon getIcon(int flags) {
|
||||
return new ImageIcon(ShowSuggestions.class.getResource("spellcheck.png"));
|
||||
}
|
||||
|
||||
public void setDescriptor(ProblemDescriptor problemDescriptor) {
|
||||
myProblemDescriptor = problemDescriptor;
|
||||
}
|
||||
}
|
||||
|
||||
-3
@@ -16,7 +16,6 @@
|
||||
package com.intellij.spellchecker.quickfixes;
|
||||
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.actionSystem.Anchor;
|
||||
import com.intellij.openapi.util.Iconable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -25,6 +24,4 @@ public interface SpellCheckerQuickFix extends LocalQuickFix, Iconable {
|
||||
|
||||
@NotNull
|
||||
Anchor getPopupActionAnchor();
|
||||
void setDescriptor(ProblemDescriptor problemDescriptor);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user