org.eclipse.xtext.ide.server.Document Java Examples

The following examples show how to use org.eclipse.xtext.ide.server.Document. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FormattingService.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.14
 */
public List<TextEdit> format(XtextResource resource, Document document, int offset, int length,
		FormattingOptions options) {
	String indent = indentationInformation.getIndentString();
	if (options != null) {
		if (options.isInsertSpaces()) {
			indent = Strings.padEnd("", options.getTabSize(), ' ');
		}
	}
	List<TextEdit> result = new ArrayList<>();
	if (this.formatter2Provider != null) {
		MapBasedPreferenceValues preferences = new MapBasedPreferenceValues();
		preferences.put("indentation", indent);
		List<ITextReplacement> replacements = format2(resource, new TextRegion(offset, length), preferences);
		for (ITextReplacement r : replacements) {
			result.add(toTextEdit(document, r.getReplacementText(), r.getOffset(), r.getLength()));
		}
	}
	return result;
}
 
Example #2
Source File: DocumentTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testOffSet_empty() {
  Document _document = new Document(Integer.valueOf(1), "");
  final Procedure1<Document> _function = (Document it) -> {
    Assert.assertEquals(0, it.getOffSet(this.position(0, 0)));
    try {
      it.getOffSet(this.position(0, 12));
      Assert.fail();
    } catch (final Throwable _t) {
      if (_t instanceof IndexOutOfBoundsException) {
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
  };
  ObjectExtensions.<Document>operator_doubleArrow(_document, _function);
}
 
Example #3
Source File: SemanticChangeProvider.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Return the IChange to set the access modifier for the given element with optional export modifier. No validation
 * of export parameter. (e.g. members)
 *
 * @param document
 *            Document to modify
 * @param element
 *            Element to modify
 * @param modifier
 *            Modifier to set
 * @param export
 *            Optional export modifier
 */
private TextEdit setAccessModifiers(Document document, ModifiableElement element, N4Modifier modifier,
		boolean export) {

	List<N4Modifier> nonAccessModifier = new ArrayList<>();
	for (N4Modifier mod : element.getDeclaredModifiers()) {
		if (!ModifierUtils.isAccessModifier(mod)) {
			nonAccessModifier.add(mod);
		}
	}

	nonAccessModifier.add(modifier);

	// Add export prefix
	var exportPrefix = "";
	if (export) {
		exportPrefix = N4JSLanguageConstants.EXPORT_KEYWORD;
		// Add additional spacing to the other modifiers
		if (nonAccessModifier.size() > 0) {
			exportPrefix += " ";
		}
	}

	return setModifiers(document, element, exportPrefix + sortedModifierString(nonAccessModifier));
}
 
Example #4
Source File: DocumentTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testUpdate_01() {
  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(Integer.valueOf(1), _normalize);
  final Procedure1<Document> _function = (Document it) -> {
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("hello world");
    _builder_1.newLine();
    _builder_1.append("bar");
    _builder_1.newLine();
    TextDocumentContentChangeEvent _change = this.change(this.position(1, 0), this.position(2, 0), "");
    Assert.assertEquals(this.normalize(_builder_1), it.applyTextDocumentChanges(
      Collections.<TextDocumentContentChangeEvent>unmodifiableList(CollectionLiterals.<TextDocumentContentChangeEvent>newArrayList(_change))).getContents());
  };
  ObjectExtensions.<Document>operator_doubleArrow(_document, _function);
}
 
Example #5
Source File: DocumentTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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(Integer.valueOf(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();
    TextDocumentContentChangeEvent _change = this.change(this.position(1, 1), this.position(1, 3), "uture");
    Assert.assertEquals(this.normalize(_builder_1), it.applyTextDocumentChanges(
      Collections.<TextDocumentContentChangeEvent>unmodifiableList(CollectionLiterals.<TextDocumentContentChangeEvent>newArrayList(_change))).getContents());
  };
  ObjectExtensions.<Document>operator_doubleArrow(_document, _function);
}
 
Example #6
Source File: DocumentTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testUpdate_03() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("hello world");
  _builder.newLine();
  _builder.append("foo");
  _builder.newLine();
  _builder.append("bar");
  String _normalize = this.normalize(_builder);
  Document _document = new Document(Integer.valueOf(1), _normalize);
  final Procedure1<Document> _function = (Document it) -> {
    TextDocumentContentChangeEvent _change = this.change(this.position(0, 0), this.position(2, 3), "");
    Assert.assertEquals("", it.applyTextDocumentChanges(
      Collections.<TextDocumentContentChangeEvent>unmodifiableList(CollectionLiterals.<TextDocumentContentChangeEvent>newArrayList(_change))).getContents());
  };
  ObjectExtensions.<Document>operator_doubleArrow(_document, _function);
}
 
Example #7
Source File: DocumentTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testApplyTextDocumentChanges_04() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("foo");
  _builder.newLine();
  _builder.append("bar");
  _builder.newLine();
  String _normalize = this.normalize(_builder);
  TextDocumentContentChangeEvent _change = this.change(this.position(0, 3), this.position(0, 3), "b");
  TextDocumentContentChangeEvent _change_1 = this.change(this.position(0, 4), this.position(0, 4), "a");
  TextDocumentContentChangeEvent _change_2 = this.change(this.position(0, 5), this.position(0, 5), "r");
  Document _applyTextDocumentChanges = new Document(Integer.valueOf(1), _normalize).applyTextDocumentChanges(
    Collections.<TextDocumentContentChangeEvent>unmodifiableList(CollectionLiterals.<TextDocumentContentChangeEvent>newArrayList(_change, _change_1, _change_2)));
  final Procedure1<Document> _function = (Document it) -> {
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("foobar");
    _builder_1.newLine();
    _builder_1.append("bar");
    _builder_1.newLine();
    Assert.assertEquals(this.normalize(_builder_1), it.getContents());
    Assert.assertEquals(2, (it.getVersion()).intValue());
  };
  ObjectExtensions.<Document>operator_doubleArrow(_applyTextDocumentChanges, _function);
}
 
Example #8
Source File: DocumentTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testUpdate_nonIncrementalChange() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("hello world");
  _builder.newLine();
  _builder.append("foo");
  _builder.newLine();
  _builder.append("bar");
  String _normalize = this.normalize(_builder);
  Document _document = new Document(Integer.valueOf(1), _normalize);
  final Procedure1<Document> _function = (Document it) -> {
    TextEdit _textEdit = this.textEdit(null, null, " foo ");
    Assert.assertEquals(" foo ", it.applyChanges(
      Collections.<TextEdit>unmodifiableList(CollectionLiterals.<TextEdit>newArrayList(_textEdit))).getContents());
  };
  ObjectExtensions.<Document>operator_doubleArrow(_document, _function);
}
 
Example #9
Source File: SignatureHelpServiceImpl.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public SignatureHelp getSignatureHelp(final Document document, final XtextResource resource, final SignatureHelpParams params, final CancelIndicator cancelIndicator) {
  final int offset = document.getOffSet(params.getPosition());
  Preconditions.<XtextResource>checkNotNull(resource, "resource");
  Preconditions.checkArgument((offset >= 0), ("offset >= 0. Was: " + Integer.valueOf(offset)));
  final EObject object = this.offsetHelper.resolveContainedElementAt(resource, offset);
  if ((object instanceof OperationCall)) {
    final String operationName = this.getOperationName(((OperationCall)object));
    boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(operationName);
    boolean _not = (!_isNullOrEmpty);
    if (_not) {
      return this.getSignatureHelp(((OperationCall)object), operationName, offset);
    }
  }
  return ISignatureHelpService.EMPTY;
}
 
Example #10
Source File: AbstractLanguageServerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected void testFormatting(final Procedure1<? super DocumentFormattingParams> paramsConfigurator, final Procedure1<? super FormattingConfiguration> configurator) {
  try {
    @Extension
    final FormattingConfiguration configuration = new FormattingConfiguration();
    configuration.setFilePath(("MyModel." + this.fileExtension));
    configurator.apply(configuration);
    final FileInfo fileInfo = this.initializeContext(configuration);
    DocumentFormattingParams _documentFormattingParams = new DocumentFormattingParams();
    final Procedure1<DocumentFormattingParams> _function = (DocumentFormattingParams it) -> {
      String _uri = fileInfo.getUri();
      TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(_uri);
      it.setTextDocument(_textDocumentIdentifier);
      if ((paramsConfigurator != null)) {
        paramsConfigurator.apply(it);
      }
    };
    DocumentFormattingParams _doubleArrow = ObjectExtensions.<DocumentFormattingParams>operator_doubleArrow(_documentFormattingParams, _function);
    final CompletableFuture<List<? extends TextEdit>> changes = this.languageServer.formatting(_doubleArrow);
    String _contents = fileInfo.getContents();
    final Document result = new Document(Integer.valueOf(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);
  }
}
 
Example #11
Source File: SemanticHighlightingRegistry.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected List<SemanticHighlightingInformation> appendEmptyLineTokens(final List<SemanticHighlightingInformation> infos, final Document document) {
  final int lineCount = document.getLineCount();
  final Function<SemanticHighlightingInformation, Integer> _function = (SemanticHighlightingInformation it) -> {
    return Integer.valueOf(it.getLine());
  };
  final HashMap<Integer, SemanticHighlightingInformation> tokens = Maps.<Integer, SemanticHighlightingInformation>newHashMap(Maps.<Integer, SemanticHighlightingInformation>uniqueIndex(infos, _function));
  ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, lineCount, true);
  for (final Integer i : _doubleDotLessThan) {
    boolean _containsKey = tokens.containsKey(i);
    boolean _not = (!_containsKey);
    if (_not) {
      SemanticHighlightingInformation _semanticHighlightingInformation = new SemanticHighlightingInformation((i).intValue(), null);
      tokens.put(i, _semanticHighlightingInformation);
    }
  }
  return IterableExtensions.<SemanticHighlightingInformation>toList(tokens.values());
}
 
Example #12
Source File: ChangeConverter2.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected void _handleReplacements(IEmfResourceChange change) {
	try {
		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
		String uri = uriExtensions.toUriString(change.getResource().getURI());
		change.getResource().save(outputStream, null);
		String newContent = new String(outputStream.toByteArray(), getCharset(change.getResource()));
		access.doRead(uri, (ILanguageServerAccess.Context context) -> {
			Document document = context.getDocument();
			Range range = new Range(document.getPosition(0), document.getPosition(document.getContents().length()));
			TextEdit textEdit = new TextEdit(range, newContent);
			return addTextEdit(uri, document, textEdit);
		}).get();
	} catch (InterruptedException | ExecutionException | IOException e) {
		throw Exceptions.sneakyThrow(e);
	}
}
 
Example #13
Source File: ContentAssistService.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected CompletionItem toCompletionItem(ContentAssistEntry entry, int caretOffset, Position caretPosition,
		Document document) {
	CompletionItem completionItem = new CompletionItem();
	String label = entry.getLabel();
	if (label == null) {
		label = entry.getProposal();
	}
	completionItem.setLabel(label);
	completionItem.setDetail(entry.getDescription());
	completionItem.setDocumentation(entry.getDocumentation());
	String prefix = entry.getPrefix();
	if (prefix == null) {
		prefix = "";
	}
	int prefixOffset = caretOffset - prefix.length();
	Position prefixPosition = document.getPosition(prefixOffset);
	completionItem.setTextEdit(new TextEdit(new Range(prefixPosition, caretPosition), entry.getProposal()));
	completionItem.setKind(translateKind(entry));
	if (!entry.getTextReplacements().isEmpty()) {
		if (completionItem.getAdditionalTextEdits() == null) {
			completionItem.setAdditionalTextEdits(new ArrayList<>(entry.getTextReplacements().size()));
		}
		entry.getTextReplacements().forEach(
				(ReplaceRegion it) -> completionItem.getAdditionalTextEdits().add(toTextEdit(it, document)));
	}
	if (ContentAssistEntry.KIND_SNIPPET.equals(entry.getKind())) {
		completionItem.setInsertTextFormat(InsertTextFormat.Snippet);
	}
	return completionItem;
}
 
Example #14
Source File: DocumentTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testOffSet() {
  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(Integer.valueOf(1), _normalize);
  final Procedure1<Document> _function = (Document it) -> {
    Assert.assertEquals(0, it.getOffSet(this.position(0, 0)));
    Assert.assertEquals(11, it.getOffSet(this.position(0, 11)));
    try {
      it.getOffSet(this.position(0, 12));
      Assert.fail();
    } catch (final Throwable _t) {
      if (_t instanceof IndexOutOfBoundsException) {
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
    Assert.assertEquals(12, it.getOffSet(this.position(1, 0)));
    Assert.assertEquals(13, it.getOffSet(this.position(1, 1)));
    Assert.assertEquals(14, it.getOffSet(this.position(1, 2)));
    Assert.assertEquals(16, it.getOffSet(this.position(2, 0)));
    Assert.assertEquals(19, it.getOffSet(this.position(2, 3)));
  };
  ObjectExtensions.<Document>operator_doubleArrow(_document, _function);
}
 
Example #15
Source File: HoverContext.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public HoverContext(Document document, XtextResource resource, int offset, ITextRegion region, EObject element) {
	this.document = document;
	this.resource = resource;
	this.offset = offset;
	this.region = region;
	this.element = element;
}
 
Example #16
Source File: RenameService2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected EObject getElementAtOffset(XtextResource xtextResource, Document document, Position caretPosition) {
	int caretOffset = document.getOffSet(caretPosition);
	EObject element = getElementWithIdentifierAt(xtextResource, caretOffset);
	if (element != null) {
		return element;
	} else {
		return getElementWithIdentifierAt(xtextResource, caretOffset - 1);
	}
}
 
Example #17
Source File: ITextRegionTransformer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public DocumentHighlight apply(final Document document, final ITextRegion region,
		final DocumentHighlightKind kind) {

	Preconditions.checkNotNull(document, "document");
	Preconditions.checkNotNull(region, "region");
	Preconditions.checkNotNull(kind, "kind");

	final int offset = region.getOffset();
	final Position start = document.getPosition(offset);
	final Position end = document.getPosition(offset + region.getLength());

	return new DocumentHighlight(new Range(start, end), kind);
}
 
Example #18
Source File: DocumentTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGetLineCount_multi() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("aaa");
  _builder.newLine();
  _builder.append("bbb");
  _builder.newLine();
  _builder.append("ccc");
  Assert.assertEquals(3, new Document(Integer.valueOf(1), _builder.toString()).getLineCount());
}
 
Example #19
Source File: DocumentTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test(expected = IndexOutOfBoundsException.class)
public void testGetLineContent_exceeds() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("aaa");
  _builder.newLine();
  _builder.append("bbb");
  _builder.newLine();
  _builder.append("ccc");
  new Document(Integer.valueOf(1), _builder.toString()).getLineContent(3);
}
 
Example #20
Source File: DocumentTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGetLineContent() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("aaa");
  _builder.newLine();
  _builder.append("bbb");
  _builder.newLine();
  _builder.append("ccc");
  Assert.assertEquals("bbb", new Document(Integer.valueOf(1), _builder.toString()).getLineContent(1));
}
 
Example #21
Source File: CustomContentAssistService.java    From solidity-ide with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected CompletionItem toCompletionItem(ContentAssistEntry entry, int caretOffset, Position caretPosition,
		Document document) {
	CompletionItem completionItem = super.toCompletionItem(entry, caretOffset, caretPosition, document);
	Either<String, MarkupContent> documentation = completionItem.getDocumentation();
	if (documentation != null && documentation.getLeft() == null && documentation.getRight()==null) {
		completionItem.setDocumentation((Either<String,MarkupContent>)null);
	}
	return completionItem;
}
 
Example #22
Source File: WorkspaceManagerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testDoRead() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("type Test {");
  _builder.newLine();
  _builder.append("    ");
  _builder.append("string foo");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final URI path = this.operator_mappedTo("MyType1.testlang", _builder);
  this.workspaceManger.doBuild(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(path)), CollectionLiterals.<URI>emptyList(), null);
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("type Test {");
  _builder_1.newLine();
  _builder_1.append("    ");
  _builder_1.append("Test foo");
  _builder_1.newLine();
  _builder_1.append("}");
  _builder_1.newLine();
  final String inMemContents = _builder_1.toString();
  this.workspaceManger.didOpen(path, Integer.valueOf(1), inMemContents).build(null);
  final Function2<Document, XtextResource, String> _function = (Document $0, XtextResource $1) -> {
    return $0.getContents();
  };
  Assert.assertEquals(inMemContents, this.workspaceManger.<String>doRead(path, _function));
}
 
Example #23
Source File: RenameTest3.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testRenameQuotedRef() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("type ^type {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("type Bar extends ^type {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final String model = _builder.toString();
    final String file = this.writeFile("foo/Foo.renametl", model);
    this.initialize();
    final TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
    final Position position = new Position(3, 19);
    PrepareRenameParams _prepareRenameParams = new PrepareRenameParams(identifier, position);
    final Range range = this.languageServer.prepareRename(_prepareRenameParams).get().getLeft();
    this.assertEquals("^type", new Document(Integer.valueOf(0), model).getSubstring(range));
    final RenameParams params = new RenameParams(identifier, position, "Foo");
    final WorkspaceEdit workspaceEdit = this.languageServer.rename(params).get();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("changes :");
    _builder_1.newLine();
    _builder_1.append("documentChanges : ");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("Foo.renametl <1> : Foo [[0, 5] .. [0, 10]]");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("Foo [[3, 17] .. [3, 22]]");
    _builder_1.newLine();
    this.assertEquals(_builder_1.toString(), this.toExpectation(workspaceEdit));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #24
Source File: RenameTest3.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testRenameAutoQuoteRef() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("type Foo {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("type Bar extends Foo {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final String model = _builder.toString();
    final String file = this.writeFile("foo/Foo.renametl", model);
    this.initialize();
    final TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
    final Position position = new Position(3, 18);
    PrepareRenameParams _prepareRenameParams = new PrepareRenameParams(identifier, position);
    final Range range = this.languageServer.prepareRename(_prepareRenameParams).get().getLeft();
    this.assertEquals("Foo", new Document(Integer.valueOf(0), model).getSubstring(range));
    final RenameParams params = new RenameParams(identifier, position, "type");
    final WorkspaceEdit workspaceEdit = this.languageServer.rename(params).get();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("changes :");
    _builder_1.newLine();
    _builder_1.append("documentChanges : ");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("Foo.renametl <1> : ^type [[0, 5] .. [0, 8]]");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("^type [[3, 17] .. [3, 20]]");
    _builder_1.newLine();
    this.assertEquals(_builder_1.toString(), this.toExpectation(workspaceEdit));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #25
Source File: RenameTest3.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testRenameQuoted() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("type ^type {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final String model = _builder.toString();
    final String file = this.writeFile("foo/Foo.renametl", model);
    this.initialize();
    final TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
    final Position position = new Position(0, 6);
    PrepareRenameParams _prepareRenameParams = new PrepareRenameParams(identifier, position);
    final Range range = this.languageServer.prepareRename(_prepareRenameParams).get().getLeft();
    this.assertEquals("^type", new Document(Integer.valueOf(0), model).getSubstring(range));
    final RenameParams params = new RenameParams(identifier, position, "Foo");
    final WorkspaceEdit workspaceEdit = this.languageServer.rename(params).get();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("changes :");
    _builder_1.newLine();
    _builder_1.append("documentChanges : ");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("Foo.renametl <1> : Foo [[0, 5] .. [0, 10]]");
    _builder_1.newLine();
    this.assertEquals(_builder_1.toString(), this.toExpectation(workspaceEdit));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #26
Source File: DiagnosticIssueConverter.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** Convert the given diagnostic to an issue. */
public Issue toIssue(URI uri, Diagnostic diagnostic, Optional<Document> document) {
	IssueImpl issue = new Issue.IssueImpl();

	issue.setSeverity(toSeverity(diagnostic.getSeverity()));

	Range range = diagnostic.getRange();
	Position sPos = range.getStart();
	Position ePos = range.getEnd();
	int offSetStart = 0;
	int offSetEnd = 0;
	if (document.isPresent()) {
		offSetStart = document.get().getOffSet(new Position(sPos.getLine() + 1, sPos.getCharacter() + 1));
		offSetEnd = document.get().getOffSet(new Position(ePos.getLine() + 1, ePos.getCharacter() + 1));
	}

	issue.setLineNumber(sPos.getLine() + 1);
	issue.setColumn(sPos.getCharacter() + 1);
	issue.setOffset(offSetStart);
	issue.setLength(offSetEnd - offSetStart);

	issue.setUriToProblem(uri);
	issue.setCode(diagnostic.getCode());
	issue.setType(CheckType.FAST);
	issue.setMessage(diagnostic.getMessage());

	return issue;
}
 
Example #27
Source File: PrepareRenameTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testPrepareRenameFqn_in_ok() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package foo.bar {");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("type A {");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("foo.bar.MyType bar");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("type MyType { }");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final String model = _builder.toString();
    this.initializeWithPrepareSupport();
    final String uri = this.writeFile("my-type-valid.testlang", model);
    TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(uri);
    Position _position = new Position(2, 14);
    final PrepareRenameParams params = new PrepareRenameParams(_textDocumentIdentifier, _position);
    final Range range = this.languageServer.prepareRename(params).get().getLeft();
    this.assertEquals("MyType", new Document(Integer.valueOf(0), model).getSubstring(range));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #28
Source File: PrepareRenameTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testPrepareRenameFqn_start_ok() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("package foo.bar {");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("type A {");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("foo.bar.MyType bar");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("  ");
    _builder.append("type MyType { }");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final String model = _builder.toString();
    this.initializeWithPrepareSupport();
    final String uri = this.writeFile("my-type-valid.testlang", model);
    TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(uri);
    Position _position = new Position(2, 12);
    final PrepareRenameParams params = new PrepareRenameParams(_textDocumentIdentifier, _position);
    final Range range = this.languageServer.prepareRename(params).get().getLeft();
    this.assertEquals("MyType", new Document(Integer.valueOf(0), model).getSubstring(range));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #29
Source File: CodeLensService.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public List<? extends CodeLens> computeCodeLenses(Document document, XtextResource resource, CodeLensParams params,
		CancelIndicator indicator) {
	CodeLens codeLens = new CodeLens();
	Command command = new Command();
	command.setCommand("do.this");
	command.setTitle("Do Awesome Stuff");
	command.setArguments(Lists.newArrayList("foo", Integer.valueOf(1), Boolean.valueOf(true)));
	codeLens.setCommand(command);
	Position _position = new Position(1, 2);
	codeLens.setData(_position);
	return Lists.newArrayList(codeLens);
}
 
Example #30
Source File: RenameTest3.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testRenameAutoQuote() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("type Foo {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final String model = _builder.toString();
    final String file = this.writeFile("foo/Foo.renametl", model);
    this.initialize();
    final TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
    final Position position = new Position(0, 6);
    PrepareRenameParams _prepareRenameParams = new PrepareRenameParams(identifier, position);
    final Range range = this.languageServer.prepareRename(_prepareRenameParams).get().getLeft();
    this.assertEquals("Foo", new Document(Integer.valueOf(0), model).getSubstring(range));
    final RenameParams params = new RenameParams(identifier, position, "type");
    final WorkspaceEdit workspaceEdit = this.languageServer.rename(params).get();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("changes :");
    _builder_1.newLine();
    _builder_1.append("documentChanges : ");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("Foo.renametl <1> : ^type [[0, 5] .. [0, 8]]");
    _builder_1.newLine();
    this.assertEquals(_builder_1.toString(), this.toExpectation(workspaceEdit));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}