Hi all,

I'd like to draw some attention to this PR:

https://github.com/apache/netbeans/pull/3209

This commit adds a query, that allows plugins to prevent files from
being indexed completely or by certain indexers.

One motivator for this is the JS indexer in combination with huge
node_modules directories. In the case of angular/typescript projects
the JS indexer does not help with development, as code assistence is
provided by the typescript LSP server. But the JS indexer is ran anyway
and creates huge scan times and big indices. With these new hooks a
plugin could limit the indexing when an angular project is detected.

There is already a Query in th similar area: Visitibity Query. The
problem with this:

Visibility Query completely hides the files, that were made invisible.
For the TypeScript case defined above I want to be able to have a look
at the JS files, if necessary, to better understand certain behavior or
read documentation.

Visibility Query hides files from all indexers. The goto file facility
in NetBeans relies on the indexer infrastructure. With visibility query
you can only hide the file completely for all indexers and not
selectively.

The implementation I use a work sind a few weeks (somewhere between 4
and 8 weeks):

------------------------------------------------------------------

public class NodeModulesExcluder implements IndexabilityQueryImplementation {
    private boolean enabled = true;
    private List<ChangeListener> changeListener = new CopyOnWriteArrayList<>();

    private static final Set<String> BLOCKED_INDEXERS = new HashSet<>();
    static {
        BLOCKED_INDEXERS.add("js");
        BLOCKED_INDEXERS.add("angular");
        BLOCKED_INDEXERS.add("requirejs");
        BLOCKED_INDEXERS.add("knockoutjs");
        BLOCKED_INDEXERS.add("TLIndexer");
        BLOCKED_INDEXERS.add("tests");
    }

    @Override
    public boolean preventIndexing(IndexabilityQueryContext iqc) {
        return enabled 
                && iqc.getIndexable().getPath().contains("/node_modules/")
                && BLOCKED_INDEXERS.contains(iqc.getIndexerName());
    }

    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
        for(ChangeListener cl: changeListener) {
            cl.stateChanged(new ChangeEvent(this));
        }
    }

    @Override
    public void addChangeListener(ChangeListener l) {
        changeListener.add(l);
    }

    @Override
    public void removeChangeListener(ChangeListener l) {
        changeListener.remove(l);
    }

    @Override
    public String getName() {
        return NodeModulesExcluder.class.getName();
    }

    @Override
    public int getVersion() {
        return 1;
    }

    @Override
    public String getStateIdentifier() {
        return "NO_STATE";
    }
}

------------------------------------------------------------------

Indexing is core infrastructure, but the first round of feedback was
received and the code updated accounting for that.

So if there is anyone interested, I'd like to draw some attention to
this.

Greetings

Matthias


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@netbeans.apache.org
For additional commands, e-mail: dev-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists



Reply via email to