Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix definition and references uri for virtual documents #2203

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading