Skip to content

Commit 8ecdea6

Browse files
committed
Refactoring spellchecker.
1 parent b0dc0e1 commit 8ecdea6

5 files changed

Lines changed: 136 additions & 138 deletions

File tree

python-spellchecker/pom.xml

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
3-
- Copyright 2013-2017 consulo.io
3+
- Copyright 2013-2025 consulo.io
44
-
55
- Licensed under the Apache License, Version 2.0 (the "License");
66
- you may not use this file except in compliance with the License.
@@ -15,44 +15,44 @@
1515
- limitations under the License.
1616
-->
1717
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
18-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
19-
<modelVersion>4.0.0</modelVersion>
20-
<parent>
21-
<groupId>consulo</groupId>
22-
<artifactId>arch.ide-api-provided</artifactId>
23-
<version>3-SNAPSHOT</version>
24-
<relativePath/>
25-
</parent>
18+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
19+
<modelVersion>4.0.0</modelVersion>
20+
<parent>
21+
<groupId>consulo</groupId>
22+
<artifactId>arch.ide-api-provided</artifactId>
23+
<version>3-SNAPSHOT</version>
24+
<relativePath/>
25+
</parent>
2626

27-
<groupId>consulo.plugin</groupId>
28-
<artifactId>consulo.python.spellchecker</artifactId>
29-
<version>3-SNAPSHOT</version>
30-
<packaging>jar</packaging>
27+
<groupId>consulo.plugin</groupId>
28+
<artifactId>consulo.python.spellchecker</artifactId>
29+
<version>3-SNAPSHOT</version>
30+
<packaging>jar</packaging>
3131

32-
<repositories>
33-
<repository>
34-
<id>consulo</id>
35-
<url>https://maven.consulo.io/repository/snapshots/</url>
36-
<snapshots>
37-
<enabled>true</enabled>
38-
<updatePolicy>interval:60</updatePolicy>
39-
</snapshots>
40-
</repository>
41-
</repositories>
32+
<repositories>
33+
<repository>
34+
<id>consulo</id>
35+
<url>https://maven.consulo.io/repository/snapshots/</url>
36+
<snapshots>
37+
<enabled>true</enabled>
38+
<updatePolicy>interval:60</updatePolicy>
39+
</snapshots>
40+
</repository>
41+
</repositories>
4242

43-
<dependencies>
44-
<dependency>
45-
<groupId>${project.groupId}</groupId>
46-
<artifactId>consulo.python-python.impl</artifactId>
47-
<version>${project.version}</version>
48-
<scope>provided</scope>
49-
</dependency>
43+
<dependencies>
44+
<dependency>
45+
<groupId>${project.groupId}</groupId>
46+
<artifactId>consulo.python-python.impl</artifactId>
47+
<version>${project.version}</version>
48+
<scope>provided</scope>
49+
</dependency>
5050

51-
<dependency>
52-
<groupId>${project.groupId}</groupId>
53-
<artifactId>com.intellij.spellchecker</artifactId>
54-
<version>${project.version}</version>
55-
<scope>provided</scope>
56-
</dependency>
57-
</dependencies>
51+
<dependency>
52+
<groupId>${project.groupId}</groupId>
53+
<artifactId>com.intellij.spellchecker</artifactId>
54+
<version>${project.version}</version>
55+
<scope>provided</scope>
56+
</dependency>
57+
</dependencies>
5858
</project>

python-spellchecker/src/main/java/consulo/python/spellchecker/PythonBundledDictionaryProvider.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
package consulo.python.spellchecker;
1817

1918
import com.intellij.spellchecker.BundledDictionaryProvider;
@@ -24,12 +23,12 @@
2423
*/
2524
@ExtensionImpl
2625
public class PythonBundledDictionaryProvider implements BundledDictionaryProvider {
27-
@Override
28-
public String[] getBundledDictionaries() {
29-
return new String[] {
30-
"python.dic", // autogenerated from python stdlib
31-
"pythonExtras.dic", // manually added
32-
"django.dic"
33-
};
34-
}
26+
@Override
27+
public String[] getBundledDictionaries() {
28+
return new String[]{
29+
"python.dic", // autogenerated from python stdlib
30+
"pythonExtras.dic", // manually added
31+
"django.dic"
32+
};
33+
}
3534
}

python-spellchecker/src/main/java/consulo/python/spellchecker/PythonSpellcheckerDictionaryGenerator.java

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
package consulo.python.spellchecker;
1817

1918
import com.intellij.spellchecker.generator.SpellCheckerDictionaryGenerator;
2019
import com.jetbrains.python.codeInsight.controlflow.ScopeOwner;
2120
import com.jetbrains.python.psi.*;
21+
import consulo.annotation.access.RequiredReadAction;
2222
import consulo.document.util.TextRange;
2323
import consulo.language.Language;
2424
import consulo.language.psi.PsiFile;
@@ -28,50 +28,57 @@
2828
import consulo.project.Project;
2929
import consulo.virtualFileSystem.VirtualFile;
3030

31-
import java.util.HashSet;
31+
import java.util.Set;
3232

3333
/**
3434
* @author yole
3535
*/
3636
public class PythonSpellcheckerDictionaryGenerator extends SpellCheckerDictionaryGenerator {
37-
public PythonSpellcheckerDictionaryGenerator(final Project project, final String dictOutputFolder) {
38-
super(project, dictOutputFolder, "python");
39-
}
37+
public PythonSpellcheckerDictionaryGenerator(Project project, String dictOutputFolder) {
38+
super(project, dictOutputFolder, "python");
39+
}
4040

41-
@Override
42-
protected void processFolder(final HashSet<String> seenNames, PsiManager manager, VirtualFile folder) {
43-
if (!myExcludedFolders.contains(folder)) {
44-
final String name = folder.getName();
45-
IdentifierTokenSplitter.getInstance().split(name, TextRange.allOf(name), textRange -> {
46-
final String word = textRange.substring(name);
47-
addSeenWord(seenNames, word, Language.ANY);
48-
});
41+
@Override
42+
protected void processFolder(Set<String> seenNames, PsiManager manager, VirtualFile folder) {
43+
if (!myExcludedFolders.contains(folder)) {
44+
String name = folder.getName();
45+
IdentifierTokenSplitter.getInstance().split(
46+
name,
47+
TextRange.allOf(name),
48+
textRange -> {
49+
String word = textRange.substring(name);
50+
addSeenWord(seenNames, word, Language.ANY);
51+
}
52+
);
53+
}
54+
super.processFolder(seenNames, manager, folder);
4955
}
50-
super.processFolder(seenNames, manager, folder);
51-
}
5256

53-
@Override
54-
protected void processFile(PsiFile file, final HashSet<String> seenNames) {
55-
file.accept(new PyRecursiveElementVisitor() {
56-
@Override
57-
public void visitPyFunction(PyFunction node) {
58-
super.visitPyFunction(node);
59-
processLeafsNames(node, seenNames);
60-
}
57+
@Override
58+
protected void processFile(PsiFile file, Set<String> seenNames) {
59+
file.accept(new PyRecursiveElementVisitor() {
60+
@Override
61+
@RequiredReadAction
62+
public void visitPyFunction(PyFunction node) {
63+
super.visitPyFunction(node);
64+
processLeafsNames(node, seenNames);
65+
}
6166

62-
@Override
63-
public void visitPyClass(PyClass node) {
64-
super.visitPyClass(node);
65-
processLeafsNames(node, seenNames);
66-
}
67+
@Override
68+
@RequiredReadAction
69+
public void visitPyClass(PyClass node) {
70+
super.visitPyClass(node);
71+
processLeafsNames(node, seenNames);
72+
}
6773

68-
@Override
69-
public void visitPyTargetExpression(PyTargetExpression node) {
70-
super.visitPyTargetExpression(node);
71-
if (PsiTreeUtil.getParentOfType(node, ScopeOwner.class) instanceof PyFile) {
72-
processLeafsNames(node, seenNames);
73-
}
74-
}
75-
});
76-
}
74+
@Override
75+
@RequiredReadAction
76+
public void visitPyTargetExpression(PyTargetExpression node) {
77+
super.visitPyTargetExpression(node);
78+
if (PsiTreeUtil.getParentOfType(node, ScopeOwner.class) instanceof PyFile) {
79+
processLeafsNames(node, seenNames);
80+
}
81+
}
82+
});
83+
}
7784
}

python-spellchecker/src/main/java/consulo/python/spellchecker/PythonSpellcheckerGenerateDictionariesAction.java

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
package consulo.python.spellchecker;
1817

1918
import com.jetbrains.python.impl.sdk.PythonSdkType;
2019
import consulo.annotation.component.ActionImpl;
2120
import consulo.annotation.component.ActionRef;
2221
import consulo.content.base.BinariesOrderRootType;
2322
import consulo.content.bundle.Sdk;
24-
import consulo.language.editor.LangDataKeys;
23+
import consulo.localize.LocalizeValue;
2524
import consulo.module.Module;
2625
import consulo.module.content.ModuleRootManager;
26+
import consulo.ui.annotation.RequiredUIAccess;
2727
import consulo.ui.ex.action.AnAction;
2828
import consulo.ui.ex.action.AnActionEvent;
2929
import consulo.virtualFileSystem.VirtualFile;
@@ -32,54 +32,47 @@
3232
* @author yole
3333
*/
3434
@ActionImpl(id = "PythonGenerateDictionaries", children = @ActionRef(id = "Internal"))
35-
public class PythonSpellcheckerGenerateDictionariesAction extends AnAction
36-
{
37-
public PythonSpellcheckerGenerateDictionariesAction()
38-
{
39-
super("Generate Python Spellchecker Dictionaries");
40-
}
35+
public class PythonSpellcheckerGenerateDictionariesAction extends AnAction {
36+
public PythonSpellcheckerGenerateDictionariesAction() {
37+
super(LocalizeValue.localizeTODO("Generate Python Spellchecker Dictionaries"));
38+
}
4139

42-
@Override
43-
public void actionPerformed(AnActionEvent e)
44-
{
45-
Module module = e.getData(LangDataKeys.MODULE);
46-
if(module == null)
47-
{
48-
return;
49-
}
50-
VirtualFile[] contentRoots = ModuleRootManager.getInstance(module).getContentRoots();
51-
if(contentRoots.length == 0)
52-
{
53-
return;
54-
}
55-
Sdk sdk = PythonSdkType.findPythonSdk(module);
56-
if(sdk == null)
57-
{
58-
return;
59-
}
40+
@Override
41+
@RequiredUIAccess
42+
public void actionPerformed(AnActionEvent e) {
43+
Module module = e.getData(Module.KEY);
44+
if (module == null) {
45+
return;
46+
}
47+
VirtualFile[] contentRoots = ModuleRootManager.getInstance(module).getContentRoots();
48+
if (contentRoots.length == 0) {
49+
return;
50+
}
51+
Sdk sdk = PythonSdkType.findPythonSdk(module);
52+
if (sdk == null) {
53+
return;
54+
}
6055

61-
final PythonSpellcheckerDictionaryGenerator generator = new PythonSpellcheckerDictionaryGenerator(module.getProject(),
62-
contentRoots[0].getPath() + "/dicts");
56+
PythonSpellcheckerDictionaryGenerator generator = new PythonSpellcheckerDictionaryGenerator(
57+
module.getProject(),
58+
contentRoots[0].getPath() + "/dicts"
59+
);
6360

64-
VirtualFile[] roots = sdk.getRootProvider().getFiles(BinariesOrderRootType.getInstance());
65-
for(VirtualFile root : roots)
66-
{
67-
if(root.getName().equals("Lib"))
68-
{
69-
generator.addFolder("python", root);
70-
generator.excludeFolder(root.findChild("test"));
71-
generator.excludeFolder(root.findChild("site-packages"));
72-
}
73-
else if(root.getName().equals("site-packages"))
74-
{
75-
VirtualFile djangoRoot = root.findChild("django");
76-
if(djangoRoot != null)
77-
{
78-
generator.addFolder("django", djangoRoot);
79-
}
80-
}
81-
}
61+
VirtualFile[] roots = sdk.getRootProvider().getFiles(BinariesOrderRootType.getInstance());
62+
for (VirtualFile root : roots) {
63+
if (root.getName().equals("Lib")) {
64+
generator.addFolder("python", root);
65+
generator.excludeFolder(root.findChild("test"));
66+
generator.excludeFolder(root.findChild("site-packages"));
67+
}
68+
else if (root.getName().equals("site-packages")) {
69+
VirtualFile djangoRoot = root.findChild("django");
70+
if (djangoRoot != null) {
71+
generator.addFolder("django", djangoRoot);
72+
}
73+
}
74+
}
8275

83-
generator.generate();
84-
}
76+
generator.generate();
77+
}
8578
}
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/**
22
* @author VISTALL
3-
* @since 24/06/2023
3+
* @since 2023-06-24
44
*/
5-
open module consulo.python.spellchecker
6-
{
7-
requires consulo.ide.api;
8-
requires com.intellij.spellchecker;
9-
requires consulo.python.language.api;
10-
requires consulo.python.impl;
5+
open module consulo.python.spellchecker {
6+
requires consulo.ide.api;
7+
requires com.intellij.spellchecker;
8+
requires consulo.python.language.api;
9+
requires consulo.python.impl;
1110
}

0 commit comments

Comments
 (0)