use of org.eclipse.lsp4j.Range in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method patch.
private String patch(String sourceText, TextDocumentContentChangeEvent change) {
Range range = change.getRange();
Position start = range.getStart();
StringReader reader = new StringReader(sourceText);
int offset = lineAndCharacterToOffset(reader, start.getLine(), start.getCharacter());
return sourceText.substring(0, offset) + change.getText() + sourceText.substring(offset + change.getRangeLength());
}
use of org.eclipse.lsp4j.Range in project vscode-nextgenas by BowlerHatLLC.
the class ActionScriptTextDocumentService method addCompilerProblem.
private void addCompilerProblem(ICompilerProblem problem, PublishDiagnosticsParams publish) {
if (!flexLibSDKContainsFalconCompiler) {
if (problem.getClass().equals(FontEmbeddingNotSupported.class)) {
//ignore this error because the framework SDK can embed fonts
return;
}
}
Diagnostic diagnostic = new Diagnostic();
DiagnosticSeverity severity = LanguageServerUtils.getDiagnosticSeverityFromCompilerProblem(problem);
diagnostic.setSeverity(severity);
Range range = LanguageServerUtils.getRangeFromSourceLocation(problem);
if (range == null) {
//fall back to an empty range
range = new Range(new Position(), new Position());
}
diagnostic.setRange(range);
diagnostic.setMessage(problem.toString());
try {
Field field = problem.getClass().getDeclaredField("errorCode");
int errorCode = (int) field.get(problem);
diagnostic.setCode(Integer.toString(errorCode));
} catch (Exception e) {
//skip it
}
List<Diagnostic> diagnostics = publish.getDiagnostics();
diagnostics.add(diagnostic);
}
use of org.eclipse.lsp4j.Range in project vscode-nextgenas by BowlerHatLLC.
the class LanguageServerUtils method getRangeFromSourceLocation.
/**
* Converts a compiler source location to a language server range. May
* return null if the line or column of the source location is -1.
*/
public static Range getRangeFromSourceLocation(ISourceLocation sourceLocation) {
int line = sourceLocation.getLine();
int column = sourceLocation.getColumn();
if (line == -1 || column == -1) {
//this is probably generated by the compiler somehow
return null;
}
Position start = new Position();
start.setLine(line);
start.setCharacter(column);
int endLine = sourceLocation.getEndLine();
int endColumn = sourceLocation.getEndColumn();
if (endLine == -1 || endColumn == -1) {
endLine = line;
endColumn = column;
}
Position end = new Position();
end.setLine(endLine);
end.setCharacter(endColumn);
Range range = new Range();
range.setStart(start);
range.setEnd(end);
return range;
}
use of org.eclipse.lsp4j.Range in project sonarlint-core by SonarSource.
the class SonarLintLanguageServer method convert.
static Optional<Diagnostic> convert(Issue issue) {
if (issue.getStartLine() != null) {
Range range = position(issue);
Diagnostic diagnostic = new Diagnostic();
DiagnosticSeverity severity = severity(issue.getSeverity());
diagnostic.setSeverity(severity);
diagnostic.setRange(range);
diagnostic.setCode(issue.getRuleKey());
diagnostic.setMessage(issue.getMessage() + " (" + issue.getRuleKey() + ")");
diagnostic.setSource(SONARLINT_SOURCE);
return Optional.of(diagnostic);
}
return Optional.empty();
}
use of org.eclipse.lsp4j.Range in project xtext-core by eclipse.
the class CodeActionService method recordWorkspaceEdit.
private WorkspaceEdit recordWorkspaceEdit(final Document doc, final XtextResource resource, final IChangeSerializer.IModification<Resource> mod) {
try {
final XtextResourceSet rs = new XtextResourceSet();
final Resource copy = rs.createResource(resource.getURI());
String _text = resource.getParseResult().getRootNode().getText();
StringInputStream _stringInputStream = new StringInputStream(_text);
copy.load(_stringInputStream, CollectionLiterals.<Object, Object>emptyMap());
this.serializer.<Resource>addModification(copy, mod);
final ArrayList<IEmfResourceChange> documentchanges = CollectionLiterals.<IEmfResourceChange>newArrayList();
this.serializer.applyModifications(CollectionBasedAcceptor.<IEmfResourceChange>of(documentchanges));
WorkspaceEdit _workspaceEdit = new WorkspaceEdit();
final Procedure1<WorkspaceEdit> _function = (WorkspaceEdit it) -> {
Iterable<ITextDocumentChange> _filter = Iterables.<ITextDocumentChange>filter(documentchanges, ITextDocumentChange.class);
for (final ITextDocumentChange documentchange : _filter) {
{
final Function1<ITextReplacement, TextEdit> _function_1 = (ITextReplacement replacement) -> {
TextEdit _textEdit = new TextEdit();
final Procedure1<TextEdit> _function_2 = (TextEdit it_1) -> {
it_1.setNewText(replacement.getReplacementText());
Position _position = doc.getPosition(replacement.getOffset());
Position _position_1 = doc.getPosition(replacement.getEndOffset());
Range _range = new Range(_position, _position_1);
it_1.setRange(_range);
};
return ObjectExtensions.<TextEdit>operator_doubleArrow(_textEdit, _function_2);
};
final List<TextEdit> edits = ListExtensions.<ITextReplacement, TextEdit>map(documentchange.getReplacements(), _function_1);
it.getChanges().put(documentchange.getNewURI().toString(), edits);
}
}
};
return ObjectExtensions.<WorkspaceEdit>operator_doubleArrow(_workspaceEdit, _function);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations