use of com.redhat.qute.ls.commons.BadLocationException in project quarkus-ls by redhat-developer.
the class QuteHighlighting method findDocumentHighlights.
public List<DocumentHighlight> findDocumentHighlights(Template template, Position position, CancelChecker cancelChecker) {
try {
List<DocumentHighlight> highlights = new ArrayList<>();
int offset = template.offsetAt(position);
Node node = template.findNodeAt(offset);
if (node == null) {
return Collections.emptyList();
}
node = QutePositionUtility.findBestNode(offset, node);
switch(node.getKind()) {
case ParameterDeclaration:
case Parameter:
highlightReferenceObjectPart(node, offset, highlights, cancelChecker);
break;
case ExpressionPart:
Part part = (Part) node;
if (part.getPartKind() == PartKind.Object) {
highlightDeclaredObject((ObjectPart) part, highlights, cancelChecker);
}
break;
case Section:
higlightSection((Section) node, offset, position, highlights, cancelChecker);
break;
default:
}
return highlights;
} catch (BadLocationException e) {
LOGGER.log(Level.SEVERE, "In QuteHighlighting the client provided Position is at a BadLocation", e);
return Collections.emptyList();
}
}
use of com.redhat.qute.ls.commons.BadLocationException in project quarkus-ls by redhat-developer.
the class QuteHover method doHover.
public CompletableFuture<Hover> doHover(Template template, Position position, SharedSettings settings, CancelChecker cancelChecker) {
cancelChecker.checkCanceled();
HoverRequest hoverRequest = null;
try {
hoverRequest = new HoverRequest(template, position, settings);
} catch (BadLocationException e) {
LOGGER.log(Level.SEVERE, "Failed creating HoverRequest", e);
return NO_HOVER;
}
Node node = hoverRequest.getNode();
if (node == null) {
return NO_HOVER;
}
switch(node.getKind()) {
case Section:
// - Start end tag definition
Section section = (Section) node;
return doHoverForSection(section, template, hoverRequest, cancelChecker);
case ParameterDeclaration:
ParameterDeclaration parameterDeclaration = (ParameterDeclaration) node;
return doHoverForParameterDeclaration(parameterDeclaration, template, hoverRequest, cancelChecker);
case ExpressionPart:
Part part = (Part) node;
return doHoverForExpressionPart(part, template, hoverRequest, cancelChecker);
case Parameter:
Parameter parameter = (Parameter) node;
return doHoverForParameter(parameter, template, hoverRequest);
default:
return NO_HOVER;
}
}
use of com.redhat.qute.ls.commons.BadLocationException in project quarkus-ls by redhat-developer.
the class QuteLinkedEditing method findLinkedEditingRanges.
public LinkedEditingRanges findLinkedEditingRanges(Template template, Position position, CancelChecker cancelChecker) {
try {
int offset = template.offsetAt(position);
Node node = template.findNodeAt(offset);
if (node == null) {
return null;
}
node = QutePositionUtility.findBestNode(offset, node);
List<Range> ranges = new ArrayList<>();
//
QuteSearchUtils.searchReferencedObjects(//
node, //
offset, (n, range) -> ranges.add(range), true, cancelChecker);
if (ranges.size() <= 1) {
return null;
}
return new LinkedEditingRanges(ranges);
} catch (BadLocationException e) {
LOGGER.log(Level.SEVERE, "In QuteLinkedEditing the client provided Position is at a BadLocation", e);
return null;
}
}
use of com.redhat.qute.ls.commons.BadLocationException in project quarkus-ls by redhat-developer.
the class QuteProject method collectInsert.
private void collectInsert(String insertParamater, Node parent, Template template, List<QuteIndex> indexes) {
if (parent.getKind() == NodeKind.Section) {
Section section = (Section) parent;
if (section.getSectionKind() == SectionKind.INSERT) {
Parameter parameter = section.getParameterAtIndex(0);
if (parameter != null) {
try {
if (insertParamater == null || insertParamater.equals(parameter.getValue())) {
Position position = template.positionAt(parameter.getStart());
Path path = createPath(template.getUri());
QuteTemplateIndex templateIndex = new QuteTemplateIndex(path, template.getTemplateId());
QuteIndex index = new QuteIndex("insert", parameter.getValue(), position, SectionKind.INSERT, templateIndex);
indexes.add(index);
}
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
}
List<Node> children = parent.getChildren();
for (Node node : children) {
collectInsert(insertParamater, node, template, indexes);
}
}
use of com.redhat.qute.ls.commons.BadLocationException in project quarkus-ls by redhat-developer.
the class QuteCodeActions method doCodeActionsForUndefinedSectionTag.
private static void doCodeActionsForUndefinedSectionTag(Template template, Diagnostic diagnostic, List<CodeAction> codeActions) {
QuteProject project = template.getProject();
if (project == null) {
return;
}
try {
String tagName = null;
JsonObject data = (JsonObject) diagnostic.getData();
if (data != null) {
tagName = data.get(DIAGNOSTIC_DATA_TAG).getAsString();
} else {
int offset = template.offsetAt(diagnostic.getRange().getStart());
Node node = template.findNodeAt(offset);
node = QutePositionUtility.findBestNode(offset, node);
if (node.getKind() == NodeKind.Section) {
Section section = (Section) node;
tagName = section.getTag();
}
}
if (tagName == null) {
return;
}
// TODO : use a settings to know the preferred file extension
String preferedFileExtension = ".html";
String tagFileUri = project.getTagsDir().resolve(tagName + preferedFileExtension).toUri().toString();
String title = MessageFormat.format(UNDEFINED_SECTION_TAG_CODEACTION_TITLE, tagName);
CodeAction createUserTagFile = CodeActionFactory.createFile(title, tagFileUri, "", diagnostic);
codeActions.add(createUserTagFile);
} catch (BadLocationException e) {
LOGGER.log(Level.SEVERE, "Creation of undefined user tag code action failed", e);
}
}
Aggregations