@@ -77,9 +77,6 @@ public class LSPUsageSearcher extends CustomUsageSearcher {
7777
7878 private static final Logger LOGGER = LoggerFactory .getLogger (LSPUsageSearcher .class );
7979
80- record ElementContext (Project project , Position position , PsiFile file ) {
81- }
82-
8380 /**
8481 * Processes all usages of the given element by querying the language server.
8582 * <p>
@@ -113,17 +110,26 @@ record ElementContext(Project project, Position position, PsiFile file) {
113110 @ Override
114111 public void processElementUsages (@ NotNull PsiElement element , @ NotNull Processor <? super Usage > processor , @ NotNull FindUsagesOptions options ) {
115112 // 1. Collect only what we need from the element inside a narrow ReadAction
116- ElementContext ctx = runCancellableReadAction (() -> {
113+ record ElementData (Project project , Position position , PsiFile file , int textOffset ) {}
114+ ElementData data = runCancellableReadAction (() -> {
117115 PsiFile file = element .getContainingFile ();
118- return new ElementContext (file .getProject (), getPosition (element , file ), file );
116+ if (file == null ) {
117+ return null ;
118+ }
119+ Position position = getPosition (element , file );
120+ if (position == null ) {
121+ return null ;
122+ }
123+ return new ElementData (element .getProject (), position , file , element .getTextOffset ());
119124 }, ApplicationManager .getApplication ());
120- Project project = ctx .project ();
121- Position position = ctx .position ();
122- PsiFile file = ctx .file ();
123-
124- if (position == null || file == null ) {
125+
126+ if (data == null ) {
125127 return ;
126128 }
129+
130+ Project project = data .project ();
131+ PsiFile file = data .file ();
132+ Position position = data .position ();
127133 if (!isUsageSupportedByLanguageServer (file )) {
128134 return ;
129135 }
@@ -200,7 +206,7 @@ public void processElementUsages(@NotNull PsiElement element, @NotNull Processor
200206
201207 LSPExternalReferencesFinder .processExternalReferences (
202208 file ,
203- element . getTextOffset (),
209+ data . textOffset (),
204210 searchScope ,
205211 reference -> processor .process (new UsageInfo2UsageAdapter (new UsageInfo (reference )))
206212 );
0 commit comments