Skip to content

Commit

Permalink
fix: null range on DocumentSymbolData (#831)
Browse files Browse the repository at this point in the history
fix: null range on DocumentSymbolData 

Fixes #830
  • Loading branch information
ericdallo authored Feb 11, 2025
1 parent 5a9c941 commit 11da5af
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@
******************************************************************************/
package com.redhat.devtools.lsp4ij.features.documentSymbol;

import javax.swing.Icon;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.impl.FakePsiElement;
import com.redhat.devtools.lsp4ij.LSPIJUtils;
import com.redhat.devtools.lsp4ij.LanguageServerItem;
import com.redhat.devtools.lsp4ij.client.features.LSPClientFeatures;

import org.eclipse.lsp4j.DocumentSymbol;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;


/**
* LSP document symbol data.
Expand All @@ -34,6 +37,7 @@ public class DocumentSymbolData extends FakePsiElement {
private final @NotNull PsiFile psiFile;
private final DocumentSymbolData parent;
private final @NotNull LanguageServerItem languageServer;
private TextRange textRange;
private DocumentSymbolData[] cachedChildren;

public DocumentSymbolData(@NotNull DocumentSymbol documentSymbol,
Expand Down Expand Up @@ -76,6 +80,14 @@ public int getTextOffset() {
return getClientFeatures().getDocumentSymbolFeature().getTextOffset(documentSymbol, psiFile);
}

@Override
public TextRange getTextRange() {
if (textRange == null) {
this.textRange = LSPIJUtils.toTextRange(documentSymbol.getRange(), LSPIJUtils.getDocument(psiFile.getVirtualFile()));
}
return textRange;
}

@Override
public void navigate(boolean requestFocus) {
getClientFeatures().getDocumentSymbolFeature().navigate(documentSymbol, psiFile, requestFocus);
Expand Down

0 comments on commit 11da5af

Please sign in to comment.