Marking certain files as special?

Answered

I'd like users to be able to mark particular files as special in some way. In my case, this is because there's a new dialect of the main language I support which is a lightweight scripting solution. Those files will require different resolution logic, but there's no easy way to reliably tell them apart. Is there a built-in solution for this or will I need something custom?

4 comments
Comment actions Permalink

Colin,

VirtualFile implements UserDataHolder interface, which allows you setting extra metadata to the object.

public static final  Key<String> MY_KEY = Key.create("MySpecialKey");

VirtualFile file = ...;
file.putUserData(MY_KEY, "value");

file.getUserData(MY_KEY);
0
Comment actions Permalink

But that would not survive the IDE being restarted, correct? Or is that persisted in the VFS somewhere?

0
Comment actions Permalink

No - for that you have to rely on the PersistentStateComponent.

0
Comment actions Permalink

For persisting attributes, see com.intellij.openapi.vfs.newvfs.FileAttribute. See com.intellij.lang.ant.ForcedAntFileAttribute for a similar solution.

0

Please sign in to leave a comment.