import org.simantics.scl.compiler.errors.Locations;
import org.simantics.scl.compiler.module.Module;
import org.simantics.scl.compiler.module.repository.UpdateListener;
+import org.simantics.scl.compiler.source.TextualModuleSource;
import org.simantics.scl.osgi.SCLOsgi;
import org.simantics.scl.runtime.SCLContext;
import org.simantics.scl.ui.editor.SCLSourceViewerConfigurationNew;
return;
String moduleName = graph.getURI(resource);
SCLContext context = SCLContext.getCurrent();
- context.put("graph", graph);
- Failable<Module> result = SCLOsgi.MODULE_REPOSITORY.getModule(moduleName, listener);
-
- if(result instanceof Failure) {
- Failure failure = (Failure)result;
- setAnnotations(Arrays.asList(failure.errors));
+ Object oldGraph = context.put("graph", graph);
+ try {
+ Failable<Module> result = SCLOsgi.MODULE_REPOSITORY.getModule(moduleName, listener);
+
+ if(result instanceof Failure) {
+ Failure failure = (Failure)result;
+ setAnnotations(Arrays.asList(failure.errors));
+ }
+ else {
+ setAnnotations(Collections.<CompilationError>emptyList());
+ }
+
+ SCLModuleEditorDocumentProvider.this.sourceViewer.updateModuleSource(
+ (TextualModuleSource)SCLOsgi.SOURCE_REPOSITORY.getModuleSource(moduleName, null));
+ } finally {
+ context.put("graph", oldGraph);
}
- else {
- setAnnotations(Collections.<CompilationError>emptyList());
- }
-
- SCLModuleEditorDocumentProvider.this.sourceViewer.updateCompletionAssistModuleName(moduleName);
}
});
}
reg.put("error", Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/error.png") );
reg.put("import_error", Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/import_error.png") );
reg.put("warning", Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/warning.png") );
+
+ reg.put("typedef_obj", Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/typedef_obj.gif") );
+ reg.put("public_co", Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/public_co.gif") );
+ reg.put("container_obj", Activator.imageDescriptorFromPlugin("org.simantics.scl.ui", "icons/container_obj.gif") );
}
@Override
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
+import org.simantics.scl.compiler.source.TextualModuleSource;
+import org.simantics.scl.osgi.SCLOsgi;
import org.simantics.scl.ui.Activator;
-import org.simantics.scl.ui.editor.completion.SCLCompletionAssistProcessor;
-import org.simantics.scl.ui.editor.completion.SCLTextEditorEnvironment;
import org.simantics.scl.ui.editor2.SCLPresentationReconciler;
+import org.simantics.scl.ui.editor2.completion.SCLContentAssistProcessor2;
public class SCLSourceViewerConfigurationNew extends SourceViewerConfiguration {
ResourceManager resourceManager;
IPreferenceStore preferenceStore;
-
- private SCLTextEditorEnvironment sclTextEditorEnvironment;
+ SCLContentAssistProcessor2 contentAssist;
public SCLSourceViewerConfigurationNew(ResourceManager resourceManager) {
this.resourceManager = resourceManager;
this.preferenceStore = EditorsUI.getPreferenceStore();
-
- this.sclTextEditorEnvironment = new SCLTextEditorEnvironment("");
+ this.contentAssist = new SCLContentAssistProcessor2(SCLOsgi.MODULE_REPOSITORY, resourceManager);
}
public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
assistant.enableAutoActivation(true);
assistant.enableAutoInsert(true);
- assistant.setContentAssistProcessor(new SCLCompletionAssistProcessor(sclTextEditorEnvironment), IDocument.DEFAULT_CONTENT_TYPE);
+ //assistant.setContentAssistProcessor(new SCLCompletionAssistProcessor(sclTextEditorEnvironment), IDocument.DEFAULT_CONTENT_TYPE);
+ assistant.setContentAssistProcessor(contentAssist, IDocument.DEFAULT_CONTENT_TYPE);
assistant.setInformationControlCreator(CREATOR);
assistant.setRestoreCompletionProposalSize(Activator.getInstance().getDialogSettings());
return assistant;
return new DefaultInformationControl(parent);
}
};
-
- public void updateCompletionAssistModuleName(String moduleName) {
- sclTextEditorEnvironment.updateModuleName(moduleName);
- }
-
-// @Override
-// public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
-// return new ContentFormatter();
-// }
-
- public SCLTextEditorEnvironment getSclTextEditorEnvironment() {
- return sclTextEditorEnvironment;
+
+ public void updateModuleSource(TextualModuleSource moduleSource) {
+ contentAssist.setModuleSource(moduleSource);
}
}
LOGGER.error("Could not open declaration {} {}", input.getModuleName(), lineAtCaret, e);
}
}
- else {
+ /*else {
// Try to find an identifier at caret
String identifierAtCaret = extractIdentifierOrSymbolAt(text, caretOffset);
if(identifierAtCaret.isEmpty())
//System.out.println("identifierAtCaret = " + identifierAtCaret + " [" + Locations.beginOf(value.definitionLocation) + ", " + Locations.endOf(value.definitionLocation) + "]");
if(value != null)
OpenSCLDefinition.scheduleOpenDefinition(value.getName().module, value.definitionLocation);
- }
+ //OpenSCLDefinition.openDefinition(value);
+ }*/
return null;
}
public boolean isDisposed() {
return disposed;
}
-
- public SCLTextEditorEnvironment getSCLTextEditorEnvironment() {
- return ((SCLSourceViewerConfigurationNew)getSourceViewerConfiguration())
- .getSclTextEditorEnvironment();
- }
public IDocument getDocument() {
return getSourceViewer().getDocument();
IDocumentPartitioner partitioner = new FastPartitioner(new SCLPartitionScanner(), SCLPartitionScanner.PARTITION_TYPES);
partitioner.connect(document);
document.setDocumentPartitioner(partitioner);
- sourceViewer.updateCompletionAssistModuleName(currentSource.getModuleName());
+ sourceViewer.updateModuleSource(currentSource);
return document;
}
--- /dev/null
+package org.simantics.scl.ui.editor2.completion;
+
+import java.util.List;
+
+import org.eclipse.jface.resource.ImageRegistry;
+import org.eclipse.jface.resource.ResourceManager;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.contentassist.CompletionProposal;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jface.text.contentassist.IContextInformationValidator;
+import org.eclipse.swt.graphics.Image;
+import org.simantics.scl.compiler.completions.Completion;
+import org.simantics.scl.compiler.completions.CompletionRequest;
+import org.simantics.scl.compiler.completions.CompletionType;
+import org.simantics.scl.compiler.completions.Completions;
+import org.simantics.scl.compiler.module.repository.ModuleRepository;
+import org.simantics.scl.compiler.source.TextualModuleSource;
+import org.simantics.scl.ui.Activator;
+
+public class SCLContentAssistProcessor2 implements IContentAssistProcessor {
+ private final ModuleRepository repository;
+ private final ResourceManager resourceManager;
+ private TextualModuleSource moduleSource;
+
+ private final Image valueImage;
+ private final Image typeImage;
+ private final Image namespaceImage;
+
+ public SCLContentAssistProcessor2(ModuleRepository repository, ResourceManager resourceManager) {
+ this.repository = repository;
+ this.resourceManager = resourceManager;
+
+ ImageRegistry imageRegistry = Activator.getInstance().getImageRegistry();
+ valueImage = resourceManager.createImage(imageRegistry.getDescriptor("public_co"));
+ typeImage = resourceManager.createImage(imageRegistry.getDescriptor("typedef_obj"));
+ namespaceImage = resourceManager.createImage(imageRegistry.getDescriptor("container_obj"));
+ }
+
+ @Override
+ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
+ String sourceText = viewer.getDocument().get();
+ List<Completion> completions = Completions.findCompletions(new CompletionRequest(repository, moduleSource, sourceText, offset, 1000));
+ ICompletionProposal[] proposals = new ICompletionProposal[completions.size()];
+ for(int i=0;i<completions.size();++i)
+ proposals[i] = convertToProposal(completions.get(i));
+ return proposals;
+ }
+
+ private Image imageByType(CompletionType completionType) {
+ switch(completionType) {
+ case Value:
+ return valueImage;
+ case Type:
+ return typeImage;
+ case Namespace:
+ return namespaceImage;
+ default:
+ return null;
+ }
+ }
+
+ private ICompletionProposal convertToProposal(Completion completion) {
+ return new CompletionProposal(completion.replacement,
+ completion.startOfReplacedText,
+ completion.lengthOfReplacedText,
+ completion.cursorPositionAfterReplacement-completion.startOfReplacedText,
+ imageByType(completion.completionType),
+ completion.getLabel(),
+ null,
+ completion.documentation);
+ }
+
+ @Override
+ public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
+ return null;
+ }
+
+ @Override
+ public char[] getCompletionProposalAutoActivationCharacters() {
+ return null;
+ }
+
+ @Override
+ public char[] getContextInformationAutoActivationCharacters() {
+ return null;
+ }
+
+ @Override
+ public String getErrorMessage() {
+ return null;
+ }
+
+ @Override
+ public IContextInformationValidator getContextInformationValidator() {
+ return null;
+ }
+
+ public void setModuleSource(TextualModuleSource moduleSource) {
+ this.moduleSource = moduleSource;
+ }
+
+}