diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 55442f0dd..6ce13a997 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -11,6 +11,7 @@ This document provides a high-level view of the changes introduced by release. - Require IntelliJ 2021.3.2 as minimum version update deprecated APIs - Add an action to open the dev tools for the JCEF preview +- Add custom AsciiDoc search scopes (#1216) === 0.37.54 diff --git a/doc/users-guide/modules/ROOT/nav.adoc b/doc/users-guide/modules/ROOT/nav.adoc index 58124ef4c..ed6bd9afc 100644 --- a/doc/users-guide/modules/ROOT/nav.adoc +++ b/doc/users-guide/modules/ROOT/nav.adoc @@ -11,6 +11,7 @@ * xref:features.adoc[] ** xref:features/editor.adoc[] ** xref:features/keymap.adoc[] +** xref:features/search.adoc[] ** xref:features/preview.adoc[] *** xref:features/preview/diagrams.adoc[] *** xref:features/preview/javafx-preview.adoc[] diff --git a/doc/users-guide/modules/ROOT/pages/features.adoc b/doc/users-guide/modules/ROOT/pages/features.adoc index e0006df25..e432401bd 100644 --- a/doc/users-guide/modules/ROOT/pages/features.adoc +++ b/doc/users-guide/modules/ROOT/pages/features.adoc @@ -26,6 +26,13 @@ The IntelliJ AsciiDoc Plugin adds to your IDE: Learn more about it in the xref:features/editor.adoc[] section. +== Advanced search functionality + +* All named elements can be searched, like section titles, IDs, and attribute names. +* Two additional search scopes to filter searching in AsciiDoc content. + +Learn more about it in the xref:features/search.adoc[] section. + == Configurable preview * Provides a two-pane AsciiDoc preview editor based on https://github.com/asciidoctor/asciidoctorj[AsciidoctorJ] with a live preview. diff --git a/doc/users-guide/modules/ROOT/pages/features/advanced/validation-in-ide.adoc b/doc/users-guide/modules/ROOT/pages/features/advanced/validation-in-ide.adoc index 37ec889b9..93f648225 100644 --- a/doc/users-guide/modules/ROOT/pages/features/advanced/validation-in-ide.adoc +++ b/doc/users-guide/modules/ROOT/pages/features/advanced/validation-in-ide.adoc @@ -30,6 +30,11 @@ Use the icon icon:question[] to read the docs of the IDE to find out about addit . In the pop-up window, the directory is preselected. Keep this selection, or choose a different scope or the whole project depending on where files should be inspected. ++ +The plugin also adds two custom scopes: _AsciiDoc files_ and _AsciiDoc files without Symlinks_, which are applied to the whole project. +The scope without symlinks avoids validating a file multiple times with duplicate error messages. +In this scope, it will only be validated once in its original location. +While this avoids duplicate error messages, it might also hide error messages that are context dependent on the symlink location. . When running this for the first time, select menu:Configure...[] to select which kind of checks to run. + diff --git a/doc/users-guide/modules/ROOT/pages/features/preview.adoc b/doc/users-guide/modules/ROOT/pages/features/preview.adoc index 57e23716a..d30559510 100644 --- a/doc/users-guide/modules/ROOT/pages/features/preview.adoc +++ b/doc/users-guide/modules/ROOT/pages/features/preview.adoc @@ -1,6 +1,8 @@ = Previewing content :description: Per default, the preview is on the right side of a vertical split screen and shows the rendered contents of the editor. +{description} + == Overview By default, the preview is on the right side of a vertical split screen. diff --git a/doc/users-guide/modules/ROOT/pages/features/search.adoc b/doc/users-guide/modules/ROOT/pages/features/search.adoc new file mode 100644 index 000000000..dc8468e0e --- /dev/null +++ b/doc/users-guide/modules/ROOT/pages/features/search.adoc @@ -0,0 +1,22 @@ += Searching content +:description: All AsciiDoc content is indexed, which allows fast searching. + +{description} + +== Overview + +There is standard functionality to search in IntelliJ: + +Users can search in a single file using kbd:[Ctrl+F]. +Replacing is done via kbd:[Ctrl+R]. + +Users can search in all files using kbd:[Ctrl+Shift+F]. +By default, the search is case-insensitive and searches for text snippets. +It can be changed to search case-sensitive and with regexes. +Replacing is available via kbd:[Ctrl+Shift+R]. + +When searching in the project, and also renaming entities, the plugin adds two new search scopes: _AsciiDoc files_ and _AsciiDoc files without Symlinks_. + +Using kbd:[Shift+Shift] (search everything), the user can search for all named elements. By default, the search returns file names. +The plugin adds the capability to include section headings, attribute names, tags and IDs. + diff --git a/src/main/java/org/asciidoc/intellij/psi/AsciiDocSearchScope.java b/src/main/java/org/asciidoc/intellij/psi/AsciiDocSearchScope.java index 78f851fac..7c5fc1d63 100644 --- a/src/main/java/org/asciidoc/intellij/psi/AsciiDocSearchScope.java +++ b/src/main/java/org/asciidoc/intellij/psi/AsciiDocSearchScope.java @@ -9,6 +9,8 @@ import org.asciidoc.intellij.file.AsciiDocFileType; import org.jetbrains.annotations.NotNull; +import java.io.IOException; +import java.nio.file.Path; import java.util.Collection; /** @@ -20,6 +22,7 @@ public class AsciiDocSearchScope extends GlobalSearchScope { private final FileIndexFacade myFileIndexFacade; + private boolean excludeSymLinks; public AsciiDocSearchScope(Project project) { super(project); @@ -30,12 +33,34 @@ public GlobalSearchScope restrictedByAsciiDocFileType() { return GlobalSearchScope.getScopeRestrictedByFileTypes(this, AsciiDocFileType.INSTANCE); } + public AsciiDocSearchScope excludeSymlinks() { + this.excludeSymLinks = true; + return this; + } + @Override public boolean contains(@NotNull VirtualFile file) { // even if isSearchInLibraries returns false, the check for isInLibraryXXX is still needed - return !myFileIndexFacade.isExcludedFile(file) && + boolean result = !myFileIndexFacade.isExcludedFile(file) && !myFileIndexFacade.isInLibraryClasses(file) && !myFileIndexFacade.isInLibrarySource(file); + + if (result && excludeSymLinks) { + if (file.isInLocalFileSystem()) { + Path path = Path.of(file.getPath()); + Path realPath; + try { + realPath = path.toRealPath(); + if (!realPath.toString().equals(path.toString())) { + result = false; + } + } catch (IOException e) { + // ignored + } + } + } + + return result; } @Override diff --git a/src/main/java/org/asciidoc/intellij/searchScopes/AsciiDocSearchScopeProvider.java b/src/main/java/org/asciidoc/intellij/searchScopes/AsciiDocSearchScopeProvider.java new file mode 100644 index 000000000..3540562c9 --- /dev/null +++ b/src/main/java/org/asciidoc/intellij/searchScopes/AsciiDocSearchScopeProvider.java @@ -0,0 +1,28 @@ +package org.asciidoc.intellij.searchScopes; + +import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.project.Project; +import com.intellij.psi.search.SearchScope; +import com.intellij.psi.search.SearchScopeProvider; +import org.asciidoc.intellij.psi.AsciiDocSearchScope; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; + +public class AsciiDocSearchScopeProvider implements SearchScopeProvider { + @Override + public @Nullable String getDisplayName() { + return "AsciiDoc"; + } + + @Override + public @NotNull List getSearchScopes(@NotNull Project project, @NotNull DataContext dataContext) { + ArrayList result = new ArrayList<>(); + result.add(new AsciiDocSearchScopeWithName(new AsciiDocSearchScope(project).excludeSymlinks(), "All files without Symlinks")); + result.add(new AsciiDocSearchScopeWithName(new AsciiDocSearchScope(project).restrictedByAsciiDocFileType(), "AsciiDoc files")); + result.add(new AsciiDocSearchScopeWithName(new AsciiDocSearchScope(project).excludeSymlinks().restrictedByAsciiDocFileType(), "AsciiDoc files without Symlinks")); + return result; + } +} diff --git a/src/main/java/org/asciidoc/intellij/searchScopes/AsciiDocSearchScopeWithName.java b/src/main/java/org/asciidoc/intellij/searchScopes/AsciiDocSearchScopeWithName.java new file mode 100644 index 000000000..663a8fb79 --- /dev/null +++ b/src/main/java/org/asciidoc/intellij/searchScopes/AsciiDocSearchScopeWithName.java @@ -0,0 +1,81 @@ +package org.asciidoc.intellij.searchScopes; + +import com.intellij.openapi.module.Module; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.SearchScope; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.Nls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.util.Objects; + +public class AsciiDocSearchScopeWithName extends GlobalSearchScope { + + private final GlobalSearchScope searchScope; + private final String name; + + public AsciiDocSearchScopeWithName(GlobalSearchScope searchScope, String name) { + this.searchScope = searchScope; + this.name = name; + } + + @Override + protected int calcHashCode() { + return Objects.hash(name); + } + + @SuppressWarnings("checkstyle:EqualsHashCode") + @Override + public boolean equals(Object obj) { + if (!(obj instanceof AsciiDocSearchScopeWithName)) { + return false; + } + return Objects.equals(name, ((AsciiDocSearchScopeWithName) obj).name); + } + + @Override + @Nls(capitalization = Nls.Capitalization.Sentence) + @NotNull + public String getDisplayName() { + return name; + } + + @Override + public @Nullable Icon getIcon() { + return searchScope.getIcon(); + } + + @Override + public boolean isSearchInModuleContent(@NotNull Module aModule) { + return searchScope.isSearchInModuleContent(aModule); + } + + @Override + public boolean isSearchInLibraries() { + return searchScope.isSearchInLibraries(); + } + + @Override + @Contract(pure = true) + @NotNull + public SearchScope intersectWith(@NotNull SearchScope scope2) { + return searchScope.intersectWith(scope2); + } + + @Override + @Contract(pure = true) + @NotNull + public GlobalSearchScope union(@NotNull SearchScope scope) { + return searchScope.union(scope); + } + + @Override + @Contract(pure = true) + public boolean contains(@NotNull VirtualFile file) { + return searchScope.contains(file); + } + +} diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index a261e8e3a..a3d630fc2 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -228,6 +228,7 @@ key="settings.asciidoc.preview.name" instance="org.asciidoc.intellij.settings.AsciiDocPreviewConfigurable"> +