Disabling the incremental project builder while using LSP

50 views Asked by At

I am using the xtext LanguageServer in my project and currently the LSP is configured to inrementalBuild which calls the GeneratorDelegate within the IncrementalBuilder class. Is there any way to disable the incrementalBuild ?

to tackle this I used the following approach by extending the IncrementalBuilder class and commenting out the GeneratorDelegate.

protected void generate(Resource resource, BuildRequest request, Source2GeneratedMapping newMappings) {
            IResourceServiceProvider serviceProvider = getResourceServiceProvider(resource);
            Set<URI> previous = newMappings.deleteSource(resource.getURI());
            URIBasedFileSystemAccess fileSystemAccess = createFileSystemAccess(serviceProvider, resource);
            fileSystemAccess.setBeforeWrite((uri, outputCfgName, contents) -> {
                newMappings.addSource2Generated(resource.getURI(), uri, outputCfgName);
                previous.remove(uri);
                request.getAfterGenerateFile().apply(resource.getURI(), uri);
                return contents;
            });
            fileSystemAccess.setBeforeDelete((uri) -> {
                newMappings.deleteGenerated(uri);
                request.getAfterDeleteFile().apply(uri);
                return true;
            });
            fileSystemAccess.setContext(resource);
            if (request.isWriteStorageResources()) {
                storeBinaryResource(resource, fileSystemAccess);
            }
            GeneratorContext generatorContext = new GeneratorContext();
            generatorContext.setCancelIndicator(request.getCancelIndicator());
            // un-comment the lines below to start incremental build.
//          GeneratorDelegate generator = serviceProvider.get(GeneratorDelegate.class);
//          generator.generate(resource, fileSystemAccess, generatorContext);
            XtextResourceSet resourceSet = request.getResourceSet();
            for (URI noLongerCreated : previous) {
                try {
                    resourceSet.getURIConverter().delete(noLongerCreated, Collections.emptyMap());
                    request.getAfterDeleteFile().apply(noLongerCreated);
                } catch (IOException e) {
                    throw new RuntimeIOException(e);
                }
            }
        }

Is there a better approach to disable the IncrementalBuilder?

0

There are 0 answers