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
9 changes: 9 additions & 0 deletions ide/lsp.client/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@
<specification-version>1.50</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.core.multiview</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>1</release-version>
<specification-version>1.71</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.libs.flexmark</code-name-base>
<build-prerequisite/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@

import java.awt.Image;
import java.beans.PropertyVetoException;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.imageio.ImageIO;
import org.netbeans.core.spi.multiview.text.MultiViewEditorElement;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.loaders.DataLoaderPool;
Expand All @@ -41,7 +39,7 @@
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.openide.util.Exceptions;
import org.openide.util.ImageUtilities;
import org.openide.util.Lookup;

/**
*
Expand All @@ -57,7 +55,7 @@ public class GenericDataObject extends MultiDataObject {
public GenericDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
super(pf, loader);
this.mimeType = FileUtil.getMIMEType(pf);
registerEditor(mimeType, false);
registerEditor(mimeType, true);
synchronized (REGISTRY) {
REGISTRY.add(new WeakReference<>(this));
}
Expand Down Expand Up @@ -144,5 +142,8 @@ public static Factory factory() {
}
};
}
}

public static MultiViewEditorElement createEditor(Lookup lkp) {
return new MultiViewEditorElement(lkp);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@
import java.util.Set;
import java.util.stream.Collectors;
import javax.swing.event.ChangeEvent;
import org.eclipse.tm4e.core.registry.IRegistryOptions;
import org.eclipse.tm4e.core.registry.Registry;
import org.netbeans.modules.lsp.client.debugger.api.RegisterDAPBreakpoints;
import org.eclipse.tm4e.core.internal.grammar.raw.RawGrammarReader;
import org.eclipse.tm4e.core.registry.IGrammarSource;
import org.netbeans.core.spi.multiview.MultiViewFactory;
import org.netbeans.modules.textmate.lexer.TextmateTokenId;
import org.netbeans.spi.navigator.NavigatorPanel;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.loaders.DataLoaderPool;
import org.openide.loaders.DataObject;
import org.openide.modules.OnStart;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle.Messages;
import org.openide.util.NbPreferences;

/**
Expand All @@ -53,13 +54,31 @@
*/
public class LanguageStorage {

/**
* Startup handler for language store. This handler reapplies the language
* descriptions at startup so that the runtime view matches the one expected
* by the running IDE. This is mostly relevant when the IDE requires new
* files (like the MultiView description when that feature was introduced).
*/
@OnStart
public static class StartupHandler implements Runnable {

@Override
public void run() {
// load language definitions and reapply them
store(load());
}

}

private static final String KEY = "language.descriptions";

static List<LanguageDescription> load() {
String descriptions = NbPreferences.forModule(LanguageServersPanel.class).get(KEY, "[]");
return Arrays.stream(new Gson().fromJson(descriptions, LanguageDescription[].class)).collect(Collectors.toList());
}

@Messages("Source=&Source")
static void store(List<LanguageDescription> languages) {
Set<String> originalMimeTypes = load().stream().map(ld -> ld.mimeType).collect(Collectors.toSet());
Set<String> mimeTypesToClear = new HashSet<>(originalMimeTypes);
Expand All @@ -74,7 +93,7 @@ static void store(List<LanguageDescription> languages) {
Exceptions.printStackTrace(ex);
}
}

for (FileObject children : mimeResolver.getChildren()) {
if ("synthetic".equals(children.getAttribute(LanguageServersPanel.class.getName()))) {
try {
Expand Down Expand Up @@ -133,6 +152,19 @@ static void store(List<LanguageDescription> languages) {
loader.setAttribute("dataObjectClass", GenericDataObject.class.getName());
loader.setAttribute("mimeType", description.mimeType);

deleteConfigFileIfExists("Editors/" + description.mimeType + "/MultiView/source.instance");
FileObject multiViewRegistration = FileUtil.createData(FileUtil.getConfigRoot(), "Editors/" + description.mimeType + "/MultiView/source.instance");
Method createMultiViewDescription = MultiViewFactory.class.getDeclaredMethod("createMultiViewDescription", Map.class);
multiViewRegistration.setAttribute("methodvalue:instanceCreate", createMultiViewDescription);
multiViewRegistration.setAttribute("instanceClass", "org.netbeans.core.multiview.ContextAwareDescription");
multiViewRegistration.setAttribute("class", GenericDataObject.class.getName());
multiViewRegistration.setAttribute("mimeType", description.mimeType);
multiViewRegistration.setAttribute("displayName", Bundle.Source());
multiViewRegistration.setAttribute("preferredID", "lsp.source");
multiViewRegistration.setAttribute("persistenceType", 1);
multiViewRegistration.setAttribute("position", 100);
multiViewRegistration.setAttribute("method", "createEditor");

FileObject icon = FileUtil.getConfigFile("Loaders/" + description.mimeType + "/Factories/icon.png");
if (icon != null) {
icon.delete();
Expand All @@ -146,8 +178,9 @@ static void store(List<LanguageDescription> languages) {
}

loader.setAttribute("iconBase", icon.getNameExt());
multiViewRegistration.setAttribute("iconBase", icon.getNameExt());
}

if (description.languageServer != null && !description.languageServer.isEmpty()) {
FileObject langServer = FileUtil.createData(FileUtil.getConfigRoot(), "Editors/" + description.mimeType + "/org-netbeans-modules-lsp-client-options-GenericLanguageServer.instance");
langServer.setAttribute("command", description.languageServer.split(" "));
Expand Down Expand Up @@ -187,6 +220,7 @@ static void store(List<LanguageDescription> languages) {
deleteConfigFileIfExists("Loaders/" + mimeType + "/Factories/data-object.instance");
deleteConfigFileIfExists("Editors/" + mimeType + "/generic-breakpoints.instance");
deleteConfigFileIfExists("Editors/" + mimeType + "/GlyphGutterActions/generic-toggle-breakpoint.shadow");
deleteConfigFileIfExists("Editors/" + mimeType + "/MultiView/source.instance");
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ private static synchronized List<MIMEResolver> declarativeResolvers() {
try {
// For now, just assume it has the right DTD. Could check this if desired.
declmimes.add(MIMEResolverImpl.forDescriptor(f)); // NOI18N
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
} catch (IOException | IllegalArgumentException ex) {
ERR.log(Level.INFO, "Failed to parse declarative MIMEResolver: " + f, ex);
}
}
}
Expand Down
Loading