use of org.eclipse.lsp4j.Position 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.Position 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.Position 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.Position in project xtext-core by eclipse.
the class Document method getPosition.
public Position getPosition(final int offset) {
final int l = this.contents.length();
if (((offset < 0) || (offset > l))) {
String _plus = (Integer.valueOf(offset) + " text was : ");
String _plus_1 = (_plus + this.contents);
throw new IndexOutOfBoundsException(_plus_1);
}
final char NL = '\n';
int line = 0;
int column = 0;
for (int i = 0; (i < l); i++) {
{
final char ch = this.contents.charAt(i);
if ((i == offset)) {
return new Position(line, column);
}
if ((ch == NL)) {
line++;
column = 0;
} else {
column++;
}
}
}
return new Position(line, column);
}
use of org.eclipse.lsp4j.Position in project xtext-core by eclipse.
the class ContentAssistService method createCompletionList.
public CompletionList createCompletionList(final Document document, final XtextResource resource, final TextDocumentPositionParams params, final CancelIndicator cancelIndicator) {
try {
final CompletionList result = new CompletionList();
result.setIsIncomplete(true);
final IdeContentProposalAcceptor acceptor = this.proposalAcceptorProvider.get();
final int caretOffset = document.getOffSet(params.getPosition());
final Position caretPosition = params.getPosition();
final TextRegion position = new TextRegion(caretOffset, 0);
try {
this.createProposals(document.getContents(), position, caretOffset, resource, acceptor);
} catch (final Throwable _t) {
if (_t instanceof Throwable) {
final Throwable t = (Throwable) _t;
boolean _isOperationCanceledException = this.operationCanceledManager.isOperationCanceledException(t);
boolean _not = (!_isOperationCanceledException);
if (_not) {
throw t;
}
} else {
throw Exceptions.sneakyThrow(_t);
}
}
final Procedure2<ContentAssistEntry, Integer> _function = (ContentAssistEntry it, Integer idx) -> {
final CompletionItem item = this.toCompletionItem(it, caretOffset, caretPosition, document);
item.setSortText(Strings.padStart(Integer.toString((idx).intValue()), 5, '0'));
List<CompletionItem> _items = result.getItems();
_items.add(item);
};
IterableExtensions.<ContentAssistEntry>forEach(acceptor.getEntries(), _function);
return result;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations