Skip to content

Commit

Permalink
Merge pull request #124 from kieler/mka/model-parsing
Browse files Browse the repository at this point in the history
Avoid unnecessary parsing of model file
  • Loading branch information
a-sr authored Oct 22, 2024
2 parents 3dd8e03 + f47ab4d commit f7e66b2
Showing 1 changed file with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import org.eclipse.xtext.ide.server.ILanguageServerExtension
import org.eclipse.xtext.ide.server.concurrent.RequestManager
import org.eclipse.xtext.resource.XtextResourceSet
import org.eclipse.xtext.util.CancelIndicator
import de.cau.cs.kieler.core.services.KielerLanguage

/**
* Implements methods to extend the LSP to allow compilation. Moreover, getting compilation systems and showing
Expand All @@ -63,6 +64,8 @@ import org.eclipse.xtext.util.CancelIndicator
class KiCoolLanguageServerExtension implements ILanguageServerExtension, KiCoolCommandExtension, ILanguageClientProvider {

protected static val LOG = Logger.getLogger(KiCoolLanguageServerExtension)

protected static val LANGUAGES = KielerLanguage.getAllRegisteredLanguages()

@Inject @Accessors(PUBLIC_GETTER) RequestManager requestManager

Expand Down Expand Up @@ -305,16 +308,29 @@ class KiCoolLanguageServerExtension implements ILanguageServerExtension, KiCoolC
* @return CS specified by the above parameters.
*/
def getCompilationSystems(String uri, int index, boolean filterForSimulation, boolean snapshotModel) {
var Object model
var Class<?> modelClass
if (snapshotModel && diagramState !== null && diagramState.getKGraphContext(uri) !== null) {
model = diagramState.getKGraphContext(uri).inputModel
modelClass = diagramState.getKGraphContext(uri).inputModel?.class
} else if (index != -1) {
model = this.objectMap.get(uri).get(index)
modelClass = this.objectMap.get(uri).get(index)?.class
} else {
// get model of model specified by uri
model = getModelFromUri(uri)
for(l : LANGUAGES) {
for(ext: l.supportedResourceExtensions) {
if (uri.endsWith(ext)) {
if (l.supportedModels.size == 1) {
modelClass = l.supportedModels.head
} else {
modelClass = l.supportedModels.get(l.supportedResourceExtensions.indexOf(ext))
}
}
}
}
if (modelClass === null) {
// get model of model specified by uri (reparsing)
modelClass = getModelFromUri(uri)?.class
}
}
return getCompilationSystems(model, filterForSimulation, snapshotModel)
return getCompilationSystems(modelClass, filterForSimulation, snapshotModel)
}

/**
Expand All @@ -324,10 +340,10 @@ class KiCoolLanguageServerExtension implements ILanguageServerExtension, KiCoolC
* @param filterForSimulation true if only simulation cs should be returned
* @return CS specified by the above parameters.
*/
def getCompilationSystems(Object model, boolean filterForSimulation, boolean snapshotModel) {
def getCompilationSystems(Class<?> modelClass, boolean filterForSimulation, boolean snapshotModel) {
this.getSystemsThread = new GetSystemsThread([
if (model !== null && model.class !== modelClassFilter) {
modelClassFilter = model.class
if (modelClass !== null && modelClass !== modelClassFilter) {
modelClassFilter = modelClass
}
var systems = getSystemModels(true, modelClassFilter)
var systemDescriptions = getSystemDescription(systems, snapshotModel)
Expand Down

0 comments on commit f7e66b2

Please sign in to comment.