use of org.eclipse.lsp4j.Range in project vscode-nextgenas by BowlerHatLLC.
the class LanguageServerUtils method getLocationFromSourceLocation.
/**
* Converts a compiler source location to a language server location. May
* return null if the line or column of the source location is -1.
*/
public static Location getLocationFromSourceLocation(ISourceLocation sourceLocation) {
Path sourceLocationPath = Paths.get(sourceLocation.getSourcePath());
Location location = new Location();
location.setUri(sourceLocationPath.toUri().toString());
Range range = getRangeFromSourceLocation(sourceLocation);
if (range == null) {
//this is probably generated by the compiler somehow
return null;
}
location.setRange(range);
return location;
}
use of org.eclipse.lsp4j.Range in project sonarlint-core by SonarSource.
the class ServerMainTest method testCodeActionRuleDescription.
@Test
public void testCodeActionRuleDescription() throws Exception {
String uri = getUri("foo.js");
VersionedTextDocumentIdentifier docId = new VersionedTextDocumentIdentifier(1);
docId.setUri(uri);
lsProxy.getTextDocumentService().didChange(new DidChangeTextDocumentParams(docId, Collections.singletonList(new TextDocumentContentChangeEvent("function foo() {\n alert('toto');\n}"))));
List<? extends Command> codeActions = lsProxy.getTextDocumentService().codeAction(new CodeActionParams(new TextDocumentIdentifier(uri), new Range(new Position(1, 4), new Position(1, 4)), new CodeActionContext(waitForDiagnostics(uri)))).get();
assertThat(codeActions).hasSize(1);
String ruleKey = (String) codeActions.get(0).getArguments().get(0);
assertThat(ruleKey).isEqualTo("javascript:S1442");
lsProxy.getWorkspaceService().executeCommand(new ExecuteCommandParams(codeActions.get(0).getCommand(), codeActions.get(0).getArguments())).get();
assertThat(client.ruleDescs).hasSize(1);
assertThat(client.ruleDescs.get(0).getKey()).isEqualTo("javascript:S1442");
assertThat(client.ruleDescs.get(0).getName()).contains("\"alert(...)\" should not be used");
assertThat(client.ruleDescs.get(0).getHtmlDescription()).contains("can be useful for debugging during development");
assertThat(client.ruleDescs.get(0).getType()).isEqualTo("VULNERABILITY");
assertThat(client.ruleDescs.get(0).getSeverity()).isEqualTo("MINOR");
}
use of org.eclipse.lsp4j.Range in project xtext-core by eclipse.
the class LanguageServerImpl method didChange.
@Override
public void didChange(final DidChangeTextDocumentParams params) {
final Function0<BuildManager.Buildable> _function = () -> {
final Function1<TextDocumentContentChangeEvent, TextEdit> _function_1 = (TextDocumentContentChangeEvent event) -> {
Range _range = event.getRange();
String _text = event.getText();
return new TextEdit(_range, _text);
};
return this.workspaceManager.didChange(this._uriExtensions.toUri(params.getTextDocument().getUri()), params.getTextDocument().getVersion(), ListExtensions.<TextDocumentContentChangeEvent, TextEdit>map(params.getContentChanges(), _function_1));
};
final Function2<CancelIndicator, BuildManager.Buildable, List<IResourceDescription.Delta>> _function_1 = (CancelIndicator cancelIndicator, BuildManager.Buildable buildable) -> {
return buildable.build(cancelIndicator);
};
this.requestManager.<BuildManager.Buildable, List<IResourceDescription.Delta>>runWrite(_function, _function_1);
}
use of org.eclipse.lsp4j.Range in project xtext-core by eclipse.
the class ChangeConverter method _handleReplacements.
protected void _handleReplacements(final IEmfResourceChange change) {
try {
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
final URI uri = change.getResource().getURI();
change.getResource().save(outputStream, null);
byte[] _byteArray = outputStream.toByteArray();
String _charset = this.getCharset(change.getResource());
final String newContent = new String(_byteArray, _charset);
final Function2<Document, XtextResource, List<TextEdit>> _function = (Document document, XtextResource resource) -> {
List<TextEdit> _xblockexpression = null;
{
Position _position = document.getPosition(0);
Position _position_1 = document.getPosition(document.getContents().length());
final Range range = new Range(_position, _position_1);
final TextEdit textEdit = new TextEdit(range, newContent);
_xblockexpression = this.addTextEdit(uri, textEdit);
}
return _xblockexpression;
};
this.workspaceManager.<List<TextEdit>>doRead(uri, _function);
} finally {
outputStream.close();
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.lsp4j.Range in project xtext-core by eclipse.
the class ChangeConverter method _handleReplacements.
protected void _handleReplacements(final ITextDocumentChange change) {
int _size = change.getReplacements().size();
boolean _greaterThan = (_size > 0);
if (_greaterThan) {
final URI uri = change.getNewURI();
final Function2<Document, XtextResource, List<TextEdit>> _function = (Document document, XtextResource resource) -> {
List<TextEdit> _xblockexpression = null;
{
final Function1<ITextReplacement, TextEdit> _function_1 = (ITextReplacement replacement) -> {
TextEdit _xblockexpression_1 = null;
{
final Position start = document.getPosition(replacement.getOffset());
int _offset = replacement.getOffset();
int _length = replacement.getLength();
int _plus = (_offset + _length);
final Position end = document.getPosition(_plus);
final Range range = new Range(start, end);
String _replacementText = replacement.getReplacementText();
_xblockexpression_1 = new TextEdit(range, _replacementText);
}
return _xblockexpression_1;
};
final List<TextEdit> textEdits = ListExtensions.<ITextReplacement, TextEdit>map(change.getReplacements(), _function_1);
_xblockexpression = this.addTextEdit(uri, ((TextEdit[]) Conversions.unwrapArray(textEdits, TextEdit.class)));
}
return _xblockexpression;
};
this.workspaceManager.<List<TextEdit>>doRead(uri, _function);
}
}
Aggregations