use of org.eclipse.xtext.ide.server.Document in project xtext-core by eclipse.
the class WorkspaceManager method doRead.
public <T extends Object> T doRead(final URI uri, final Function2<? super Document, ? super XtextResource, ? extends T> work) {
final URI resourceURI = uri.trimFragment();
final ProjectManager projectMnr = this.getProjectManager(resourceURI);
Resource _resource = null;
if (projectMnr != null) {
_resource = projectMnr.getResource(resourceURI);
}
final XtextResource resource = ((XtextResource) _resource);
if ((resource == null)) {
return work.apply(null, null);
}
Document doc = this.getDocument(resource);
Resource _resource_1 = projectMnr.getResource(resourceURI);
return work.apply(doc, ((XtextResource) _resource_1));
}
use of org.eclipse.xtext.ide.server.Document in project xtext-core by eclipse.
the class DocumentTest method testUpdate_02.
@Test
public void testUpdate_02() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("hello world");
_builder.newLine();
_builder.append("foo");
_builder.newLine();
_builder.append("bar");
_builder.newLine();
String _normalize = this.normalize(_builder);
Document _document = new Document(1, _normalize);
final Procedure1<Document> _function = (Document it) -> {
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("hello world");
_builder_1.newLine();
_builder_1.append("future");
_builder_1.newLine();
_builder_1.append("bar");
_builder_1.newLine();
TextEdit _change = this.change(this.position(1, 1), this.position(1, 3), "uture");
Assert.assertEquals(this.normalize(_builder_1), it.applyChanges(Collections.<TextEdit>unmodifiableList(CollectionLiterals.<TextEdit>newArrayList(_change))).getContents());
};
ObjectExtensions.<Document>operator_doubleArrow(_document, _function);
}
use of org.eclipse.xtext.ide.server.Document in project xtext-core by eclipse.
the class AbstractLanguageServerTest method testRangeFormatting.
protected void testRangeFormatting(final Procedure1<? super DocumentRangeFormattingParams> paramsConfigurator, final Procedure1<? super RangeFormattingConfiguration> configurator) {
try {
@Extension final RangeFormattingConfiguration configuration = new RangeFormattingConfiguration();
configuration.setFilePath(("MyModel." + this.fileExtension));
configurator.apply(configuration);
final FileInfo fileInfo = this.initializeContext(configuration);
DocumentRangeFormattingParams _documentRangeFormattingParams = new DocumentRangeFormattingParams();
final Procedure1<DocumentRangeFormattingParams> _function = (DocumentRangeFormattingParams it) -> {
String _uri = fileInfo.getUri();
TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(_uri);
it.setTextDocument(_textDocumentIdentifier);
it.setRange(configuration.getRange());
if ((paramsConfigurator != null)) {
paramsConfigurator.apply(it);
}
};
DocumentRangeFormattingParams _doubleArrow = ObjectExtensions.<DocumentRangeFormattingParams>operator_doubleArrow(_documentRangeFormattingParams, _function);
final CompletableFuture<List<? extends TextEdit>> changes = this.languageServer.rangeFormatting(_doubleArrow);
String _contents = fileInfo.getContents();
final Document result = new Document(1, _contents).applyChanges(ListExtensions.<TextEdit>reverse(CollectionLiterals.<TextEdit>newArrayList(((TextEdit[]) Conversions.unwrapArray(changes.get(), TextEdit.class)))));
this.assertEqualsStricter(configuration.getExpectedText(), result.getContents());
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.ide.server.Document in project xtext-core by eclipse.
the class DefaultDocumentHighlightService method getDocumentHighlights.
@Override
public List<DocumentHighlight> getDocumentHighlights(final XtextResource resource, final int offset) {
if (resource == null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.warn("Resource was null.");
}
return emptyList();
}
final URI uri = resource.getURI();
if (offset < 0) {
if (LOGGER.isDebugEnabled()) {
LOGGER.warn("Invalid offset argument. Offset must be a non-negative integer for resource: " + uri);
}
return emptyList();
}
final IParseResult parseResult = resource.getParseResult();
if (parseResult == null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.warn("Parse result was null for resource: " + uri);
}
return emptyList();
}
final ICompositeNode rootNode = parseResult.getRootNode();
final String docContent = rootNode.getText();
final int docLength = docContent.length();
if (offset >= docLength) {
if (LOGGER.isDebugEnabled()) {
LOGGER.warn("Offset exceeds document lenght. Document was " + docLength + " and offset was: " + offset + " for resource: " + uri);
}
return emptyList();
}
final EObject selectedElemnt = offsetHelper.resolveElementAt(resource, offset);
if (!isDocumentHighlightAvailableFor(selectedElemnt, resource, offset)) {
return emptyList();
}
final Supplier<Document> docSupplier = Suppliers.memoize(() -> new Document(UNUSED_VERSION, docContent));
Iterable<URI> targetURIs = getTargetURIs(selectedElemnt);
if (!(targetURIs instanceof TargetURIs)) {
final TargetURIs result = targetURIsProvider.get();
result.addAllURIs(targetURIs);
targetURIs = result;
}
final Builder<DocumentHighlight> resultBuilder = ImmutableList.<DocumentHighlight>builder();
final Acceptor acceptor = (Acceptor2) (source, sourceURI, eReference, index, targetOrProxy, targetURI) -> {
final ITextRegion region = locationInFileProvider.getSignificantTextRegion(source, eReference, index);
if (!isNullOrEmpty(region)) {
resultBuilder.add(textRegionTransformer.apply(docSupplier.get(), region, DocumentHighlightKind.Read));
}
};
referenceFinder.findReferences((TargetURIs) targetURIs, resource, acceptor, new NullProgressMonitor());
if (resource.equals(selectedElemnt.eResource())) {
final ITextRegion region = locationInFileProvider.getSignificantTextRegion(selectedElemnt);
if (!isNullOrEmpty(region)) {
resultBuilder.add(textRegionTransformer.apply(docSupplier.get(), region, DocumentHighlightKind.Write));
}
}
return FluentIterable.from(resultBuilder.build()).toSortedList(comparator);
}
use of org.eclipse.xtext.ide.server.Document in project xtext-core by eclipse.
the class LanguageServerImpl method resolveCodeLens.
@Override
public CompletableFuture<CodeLens> resolveCodeLens(final CodeLens unresolved) {
final URI uri = this.uninstallURI(unresolved);
if ((uri == null)) {
return CompletableFuture.<CodeLens>completedFuture(unresolved);
}
final Function1<CancelIndicator, CodeLens> _function = (CancelIndicator cancelIndicator) -> {
final IResourceServiceProvider resourceServiceProvider = this.languagesRegistry.getResourceServiceProvider(uri);
ICodeLensResolver _get = null;
if (resourceServiceProvider != null) {
_get = resourceServiceProvider.<ICodeLensResolver>get(ICodeLensResolver.class);
}
final ICodeLensResolver resolver = _get;
if ((resolver == null)) {
return unresolved;
}
final Function2<Document, XtextResource, CodeLens> _function_1 = (Document document, XtextResource resource) -> {
final CodeLens result = resolver.resolveCodeLens(document, resource, unresolved, cancelIndicator);
return result;
};
return this.workspaceManager.<CodeLens>doRead(uri, _function_1);
};
return this.requestManager.<CodeLens>runRead(_function);
}
Aggregations