Skip to content

Commit

Permalink
fix: fix definition and references uri for virtual documents
Browse files Browse the repository at this point in the history
Signed-off-by: Aman Prashant <aman.prashant@broadcom.com>
  • Loading branch information
ap891843 committed Jan 15, 2024
1 parent 721a498 commit 4960389
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public DefinitionHandler(AsyncAnalysisService asyncAnalysisService, DocumentMode
*/
public Either<List<? extends Location>, List<? extends LocationLink>> definition(DefinitionParams params) throws ExecutionException, InterruptedException {
CobolDocumentModel doc = documentModelService.get(uriDecodeService.decode(params.getTextDocument().getUri()));
return Either.forLeft(occurrences.findDefinitions(doc, params));
List<Location> definitions = occurrences.findDefinitions(doc, params);
return Either.forLeft(HandlerUtility.mapToOriginalLocation(definitions, uriDecodeService));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2024 Broadcom.
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Broadcom, Inc. - initial API and implementation
*
*/
package org.eclipse.lsp.cobol.lsp.handlers.text;

import java.util.List;
import java.util.stream.Collectors;
import lombok.experimental.UtilityClass;
import org.eclipse.lsp.cobol.service.UriDecodeService;
import org.eclipse.lsp4j.Location;

/**
* Class with utility methods for {@link org.eclipse.lsp.cobol.lsp.LspEvent} handlers
*/
@UtilityClass
public class HandlerUtility {
/**
* Maps the provided location to the original location which triggered the request.
* @param decodedLocations locations with decoded uri's
* @param service {@link UriDecodeService}
* @return mapped locations
*/
List<Location> mapToOriginalLocation(List<Location> decodedLocations, UriDecodeService service) {
return decodedLocations.stream().map(loc -> {
loc.setUri(service.getOriginalUri(loc.getUri()));
return loc;
}).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public ReferencesHandler(AsyncAnalysisService asyncAnalysisService, Occurrences
*/
public List<? extends Location> references(ReferenceParams params) throws ExecutionException, InterruptedException {
String uri = uriDecodeService.decode(params.getTextDocument().getUri());
return occurrences.findReferences(documentModelService.get(uri), params, params.getContext());
List<Location> references = occurrences.findReferences(documentModelService.get(uri), params, params.getContext());
return HandlerUtility.mapToOriginalLocation(references, uriDecodeService);
}

/**
Expand Down

0 comments on commit 4960389

Please sign in to comment.