Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 37 additions & 37 deletions python-spellchecker/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 2013-2017 consulo.io
- Copyright 2013-2025 consulo.io
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
Expand All @@ -15,44 +15,44 @@
- limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>consulo</groupId>
<artifactId>arch.ide-api-provided</artifactId>
<version>3-SNAPSHOT</version>
<relativePath/>
</parent>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>consulo</groupId>
<artifactId>arch.ide-api-provided</artifactId>
<version>3-SNAPSHOT</version>
<relativePath/>
</parent>

<groupId>consulo.plugin</groupId>
<artifactId>consulo.python.spellchecker</artifactId>
<version>3-SNAPSHOT</version>
<packaging>jar</packaging>
<groupId>consulo.plugin</groupId>
<artifactId>consulo.python.spellchecker</artifactId>
<version>3-SNAPSHOT</version>
<packaging>jar</packaging>

<repositories>
<repository>
<id>consulo</id>
<url>https://maven.consulo.io/repository/snapshots/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>interval:60</updatePolicy>
</snapshots>
</repository>
</repositories>
<repositories>
<repository>
<id>consulo</id>
<url>https://maven.consulo.io/repository/snapshots/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>interval:60</updatePolicy>
</snapshots>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>consulo.python-python.impl</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>consulo.python-python.impl</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>com.intellij.spellchecker</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>com.intellij.spellchecker</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package consulo.python.spellchecker;

import com.intellij.spellchecker.BundledDictionaryProvider;
Expand All @@ -24,12 +23,12 @@
*/
@ExtensionImpl
public class PythonBundledDictionaryProvider implements BundledDictionaryProvider {
@Override
public String[] getBundledDictionaries() {
return new String[] {
"python.dic", // autogenerated from python stdlib
"pythonExtras.dic", // manually added
"django.dic"
};
}
@Override
public String[] getBundledDictionaries() {
return new String[]{
"python.dic", // autogenerated from python stdlib
"pythonExtras.dic", // manually added
"django.dic"
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package consulo.python.spellchecker;

import com.intellij.spellchecker.generator.SpellCheckerDictionaryGenerator;
import com.jetbrains.python.codeInsight.controlflow.ScopeOwner;
import com.jetbrains.python.psi.*;
import consulo.annotation.access.RequiredReadAction;
import consulo.document.util.TextRange;
import consulo.language.Language;
import consulo.language.psi.PsiFile;
Expand All @@ -28,50 +28,57 @@
import consulo.project.Project;
import consulo.virtualFileSystem.VirtualFile;

import java.util.HashSet;
import java.util.Set;

/**
* @author yole
*/
public class PythonSpellcheckerDictionaryGenerator extends SpellCheckerDictionaryGenerator {
public PythonSpellcheckerDictionaryGenerator(final Project project, final String dictOutputFolder) {
super(project, dictOutputFolder, "python");
}
public PythonSpellcheckerDictionaryGenerator(Project project, String dictOutputFolder) {
super(project, dictOutputFolder, "python");
}

@Override
protected void processFolder(final HashSet<String> seenNames, PsiManager manager, VirtualFile folder) {
if (!myExcludedFolders.contains(folder)) {
final String name = folder.getName();
IdentifierTokenSplitter.getInstance().split(name, TextRange.allOf(name), textRange -> {
final String word = textRange.substring(name);
addSeenWord(seenNames, word, Language.ANY);
});
@Override
protected void processFolder(Set<String> seenNames, PsiManager manager, VirtualFile folder) {
if (!myExcludedFolders.contains(folder)) {
String name = folder.getName();
IdentifierTokenSplitter.getInstance().split(
name,
TextRange.allOf(name),
textRange -> {
String word = textRange.substring(name);
addSeenWord(seenNames, word, Language.ANY);
}
);
}
super.processFolder(seenNames, manager, folder);
}
super.processFolder(seenNames, manager, folder);
}

@Override
protected void processFile(PsiFile file, final HashSet<String> seenNames) {
file.accept(new PyRecursiveElementVisitor() {
@Override
public void visitPyFunction(PyFunction node) {
super.visitPyFunction(node);
processLeafsNames(node, seenNames);
}
@Override
protected void processFile(PsiFile file, Set<String> seenNames) {
file.accept(new PyRecursiveElementVisitor() {
@Override
@RequiredReadAction
public void visitPyFunction(PyFunction node) {
super.visitPyFunction(node);
processLeafsNames(node, seenNames);
}

@Override
public void visitPyClass(PyClass node) {
super.visitPyClass(node);
processLeafsNames(node, seenNames);
}
@Override
@RequiredReadAction
public void visitPyClass(PyClass node) {
super.visitPyClass(node);
processLeafsNames(node, seenNames);
}

@Override
public void visitPyTargetExpression(PyTargetExpression node) {
super.visitPyTargetExpression(node);
if (PsiTreeUtil.getParentOfType(node, ScopeOwner.class) instanceof PyFile) {
processLeafsNames(node, seenNames);
}
}
});
}
@Override
@RequiredReadAction
public void visitPyTargetExpression(PyTargetExpression node) {
super.visitPyTargetExpression(node);
if (PsiTreeUtil.getParentOfType(node, ScopeOwner.class) instanceof PyFile) {
processLeafsNames(node, seenNames);
}
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package consulo.python.spellchecker;

import com.jetbrains.python.impl.sdk.PythonSdkType;
import consulo.annotation.component.ActionImpl;
import consulo.annotation.component.ActionRef;
import consulo.content.base.BinariesOrderRootType;
import consulo.content.bundle.Sdk;
import consulo.language.editor.LangDataKeys;
import consulo.localize.LocalizeValue;
import consulo.module.Module;
import consulo.module.content.ModuleRootManager;
import consulo.ui.annotation.RequiredUIAccess;
import consulo.ui.ex.action.AnAction;
import consulo.ui.ex.action.AnActionEvent;
import consulo.virtualFileSystem.VirtualFile;
Expand All @@ -32,54 +32,47 @@
* @author yole
*/
@ActionImpl(id = "PythonGenerateDictionaries", children = @ActionRef(id = "Internal"))
public class PythonSpellcheckerGenerateDictionariesAction extends AnAction
{
public PythonSpellcheckerGenerateDictionariesAction()
{
super("Generate Python Spellchecker Dictionaries");
}
public class PythonSpellcheckerGenerateDictionariesAction extends AnAction {
public PythonSpellcheckerGenerateDictionariesAction() {
super(LocalizeValue.localizeTODO("Generate Python Spellchecker Dictionaries"));
}

@Override
public void actionPerformed(AnActionEvent e)
{
Module module = e.getData(LangDataKeys.MODULE);
if(module == null)
{
return;
}
VirtualFile[] contentRoots = ModuleRootManager.getInstance(module).getContentRoots();
if(contentRoots.length == 0)
{
return;
}
Sdk sdk = PythonSdkType.findPythonSdk(module);
if(sdk == null)
{
return;
}
@Override
@RequiredUIAccess
public void actionPerformed(AnActionEvent e) {
Module module = e.getData(Module.KEY);
if (module == null) {
return;
}
VirtualFile[] contentRoots = ModuleRootManager.getInstance(module).getContentRoots();
if (contentRoots.length == 0) {
return;
}
Sdk sdk = PythonSdkType.findPythonSdk(module);
if (sdk == null) {
return;
}

final PythonSpellcheckerDictionaryGenerator generator = new PythonSpellcheckerDictionaryGenerator(module.getProject(),
contentRoots[0].getPath() + "/dicts");
PythonSpellcheckerDictionaryGenerator generator = new PythonSpellcheckerDictionaryGenerator(
module.getProject(),
contentRoots[0].getPath() + "/dicts"
);

VirtualFile[] roots = sdk.getRootProvider().getFiles(BinariesOrderRootType.getInstance());
for(VirtualFile root : roots)
{
if(root.getName().equals("Lib"))
{
generator.addFolder("python", root);
generator.excludeFolder(root.findChild("test"));
generator.excludeFolder(root.findChild("site-packages"));
}
else if(root.getName().equals("site-packages"))
{
VirtualFile djangoRoot = root.findChild("django");
if(djangoRoot != null)
{
generator.addFolder("django", djangoRoot);
}
}
}
VirtualFile[] roots = sdk.getRootProvider().getFiles(BinariesOrderRootType.getInstance());
for (VirtualFile root : roots) {
if (root.getName().equals("Lib")) {
generator.addFolder("python", root);
generator.excludeFolder(root.findChild("test"));
generator.excludeFolder(root.findChild("site-packages"));
}
else if (root.getName().equals("site-packages")) {
VirtualFile djangoRoot = root.findChild("django");
if (djangoRoot != null) {
generator.addFolder("django", djangoRoot);
}
}
}

generator.generate();
}
generator.generate();
}
}
13 changes: 6 additions & 7 deletions python-spellchecker/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/**
* @author VISTALL
* @since 24/06/2023
* @since 2023-06-24
*/
open module consulo.python.spellchecker
{
requires consulo.ide.api;
requires com.intellij.spellchecker;
requires consulo.python.language.api;
requires consulo.python.impl;
open module consulo.python.spellchecker {
requires consulo.ide.api;
requires com.intellij.spellchecker;
requires consulo.python.language.api;
requires consulo.python.impl;
}
Loading