Skip to content

Commit

Permalink
Fix/hover copybook (#2381)
Browse files Browse the repository at this point in the history
* fix: show hover for user supplied copybooks
  • Loading branch information
ap891843 authored Jul 16, 2024
1 parent 0d8752f commit 8bd8a71
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void test() {
ImmutableList.of(),
ImmutableMap.of()));
SourceUnitGraph documentGraph = mock(SourceUnitGraph.class);
when(documentGraph.isCopybook(anyString())).thenReturn(false);
when(documentGraph.isUserSuppliedCopybook(anyString())).thenReturn(false);
final Hover mapHover =
new VariableHover(new UriDecodeService())
.getHover(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private synchronized void updateDocumentGraphUponCompletion(
CobolDocumentModel model, EventSource eventSource) {
updateGraphNodes(model, eventSource);
invalidateGraphLinks(model.getUri());
if (isCopybook(model.getUri()) || model.getAnalysisResult() == null) {
if (isUserSuppliedCopybook(model.getUri()) || model.getAnalysisResult() == null) {
return;
}
updateGraphLink(model, eventSource);
Expand Down Expand Up @@ -178,7 +178,7 @@ private void invalidateCopybookIndexedCache(String referUri, String copybookUri)
* @param uri document uri
* @return true if copybook, false otherwise.
*/
public boolean isCopybook(String uri) {
public boolean isUserSuppliedCopybook(String uri) {
return documentGraphIndexedByCopybook.keySet().stream()
.anyMatch(
copyUri -> {
Expand All @@ -187,10 +187,6 @@ public boolean isCopybook(String uri) {
copyUri = copyUri.replace(" ", "%20");
return new URL(decodeUri).sameFile(new URL(copyUri));
} catch (IOException e) {
if (ImplicitCodeUtils.isImplicit(copyUri)) {
LOG.debug("{} is a implicit copybook", copyUri);
return true;
}
LOG.error("IOException encountered while comparing paths {} and {}", copyUri, uri);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void didChange(
return;
}
String text = params.getContentChanges().get(0).getText();
if (sourceUnitGraph.isCopybook(uri)) {
if (sourceUnitGraph.isUserSuppliedCopybook(uri)) {
sourceUnitGraph.updateContent(uri, text);
List<String> allAssociatedFilesForACopybook = sourceUnitGraph.getAllAssociatedFilesForACopybook(uri);
asyncAnalysisService.reanalyseCopybooksAssociatedPrograms(allAssociatedFilesForACopybook, uri, text, SourceUnitGraph.EventSource.IDE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public CopybookHoverProvider(UriDecodeService uriDecodeService) {
public Hover getHover(@Nullable CobolDocumentModel document, @NonNull TextDocumentPositionParams position, SourceUnitGraph documentGraph) {
String uri = uriDecodeService.decode(position.getTextDocument().getUri());
Position hoverPosition = position.getPosition();
if (documentGraph.isCopybook(uri)) {
if (documentGraph.isUserSuppliedCopybook(uri)) {
List<SourceUnitGraph.NodeV> containedCopybookNode = documentGraph.getInjectedCopybookNode(uri, hoverPosition);
if (!containedCopybookNode.isEmpty()) {
return getHover(containedCopybookNode.get(0).getContent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ElementOccurrences(SourceUnitGraph sourceUnitGraph, UriDecodeService uriD
public @NonNull List<Location> findDefinitions(
@NonNull CobolDocumentModel document, @NonNull TextDocumentPositionParams position) {
String uri = uriDecodeService.decode(position.getTextDocument().getUri());
if (sourceUnitGraph.isCopybook(uri)) {
if (sourceUnitGraph.isUserSuppliedCopybook(uri)) {
return getCopybookLocation(position, uri);
}
return SymbolsRepository.findElementByPosition(uri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void testNotifyState() {

assertEquals(initialDocumentText, sourceUnitGraph.getContent(URI));
assertTrue(sourceUnitGraph.isFileOpened(URI));
assertFalse(sourceUnitGraph.isCopybook(URI));
assertFalse(sourceUnitGraph.isUserSuppliedCopybook(URI));

sourceUnitGraph.updateContent(URI, updatedContent);
assertEquals(updatedContent, sourceUnitGraph.getContent(URI));
Expand Down Expand Up @@ -103,10 +103,10 @@ void testLinksBetweenCopybookAndSourceCode() {
AnalysisState.COMPLETED, model, SourceUnitGraph.EventSource.FILE_SYSTEM);

assertEquals("COPY 3 TEXT", sourceUnitGraph.getCopyNodeContent(copyNode3));
assertTrue(sourceUnitGraph.isCopybook(copy1Uri));
assertTrue(sourceUnitGraph.isCopybook(copy2Uri));
assertTrue(sourceUnitGraph.isCopybook(copy3Uri));
assertFalse(sourceUnitGraph.isCopybook(URI));
assertTrue(sourceUnitGraph.isUserSuppliedCopybook(copy1Uri));
assertTrue(sourceUnitGraph.isUserSuppliedCopybook(copy2Uri));
assertTrue(sourceUnitGraph.isUserSuppliedCopybook(copy3Uri));
assertFalse(sourceUnitGraph.isUserSuppliedCopybook(URI));

List<SourceUnitGraph.NodeV> injectedCopybookNode =
sourceUnitGraph.getInjectedCopybookNode(URI, new Position(2, 9));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ void testGetHover() {
SourceUnitGraph sourceUnitGraph = mock(SourceUnitGraph.class);
copybookHoverProvider.getHover(mock(CobolDocumentModel.class), position, sourceUnitGraph);

verify(sourceUnitGraph, times(1)).isCopybook(any());
verify(sourceUnitGraph, times(1)).isUserSuppliedCopybook(any());
}

@Test
void testGetHover_graphIsCopybook() {
TextDocumentPositionParams position = mock(TextDocumentPositionParams.class);
when(position.getTextDocument()).thenReturn(mock(TextDocumentIdentifier.class));
SourceUnitGraph sourceUnitGraph = mock(SourceUnitGraph.class);
when(sourceUnitGraph.isCopybook(any())).thenReturn(true);
when(sourceUnitGraph.isUserSuppliedCopybook(any())).thenReturn(true);
SourceUnitGraph.NodeV nodeV = mock(SourceUnitGraph.NodeV.class);
List<SourceUnitGraph.NodeV> containedCopybookNode = new ArrayList<>();
containedCopybookNode.add(nodeV);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class VariableHoverTest {
@BeforeEach
void setUp() {
this.documentGraph = mock(SourceUnitGraph.class);
when(documentGraph.isCopybook(anyString())).thenReturn(false);
when(documentGraph.isUserSuppliedCopybook(anyString())).thenReturn(false);
}

private static final String HEADER =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ void findHighlights() {
void variousCases(
AnalysisResult analysisResult, Position position, List<Location> expectedLocations) {
SourceUnitGraph documentGraph = mock(SourceUnitGraph.class);
when(documentGraph.isCopybook(anyString())).thenReturn(false);
when(documentGraph.isUserSuppliedCopybook(anyString())).thenReturn(false);
List<Location> actualLocations =
new ElementOccurrences(documentGraph, uriDecodeService)
.findReferences(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void assertHover(AnalysisResult result) {
HoverProvider provider = new VariableHover(uriDecodeService);

SourceUnitGraph documentGraph = mock(SourceUnitGraph.class);
when(documentGraph.isCopybook(anyString())).thenReturn(false);
when(documentGraph.isUserSuppliedCopybook(anyString())).thenReturn(false);
final Hover actual =
provider.getHover(
new CobolDocumentModel("", "", result),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void test() {
DefinedAndUsedStructure ctx = mock(DefinedAndUsedStructure.class);
when(ctx.getDefinitions()).thenReturn(Collections.singletonList(expectedDef));
SourceUnitGraph documentGraph = mock(SourceUnitGraph.class);
when(documentGraph.isCopybook(anyString())).thenReturn(false);
when(documentGraph.isUserSuppliedCopybook(anyString())).thenReturn(false);

try (MockedStatic mocked = mockStatic(SymbolsRepository.class)) {
mocked.when(() -> SymbolsRepository.findElementByPosition(eq(DOCUMENT_URI), eq(document.getAnalysisResult()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private void assertHover(AnalysisResult result) {
when(uriDecodeService.decode(DOCUMENT_URI)).thenReturn(DOCUMENT_URI);
SourceUnitGraph documentGraph = mock(SourceUnitGraph.class);
HoverProvider provider = new VariableHover(uriDecodeService);
when(documentGraph.isCopybook(anyString())).thenReturn(false);
when(documentGraph.isUserSuppliedCopybook(anyString())).thenReturn(false);
final Hover actual =
provider.getHover(
new CobolDocumentModel("", "", result),
Expand Down

0 comments on commit 8bd8a71

Please sign in to comment.