Skip to content

Commit 1a0bb2f

Browse files
committed
fix: unbounded occurs support added
1 parent f2a09a2 commit 1a0bb2f

File tree

4 files changed

+67
-25
lines changed

4 files changed

+67
-25
lines changed

server/engine/src/main/java/org/eclipse/lsp/cobol/service/CobolLanguageServer.java

+23-21
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,16 @@ public class CobolLanguageServer implements LanguageServer {
6767
@Inject
6868
@SuppressWarnings("squid:S107")
6969
CobolLanguageServer(
70-
TextDocumentService textService,
71-
WorkspaceService workspaceService,
72-
WatcherService watchingService,
73-
SettingsService settingsService,
74-
LocaleStore localeStore,
75-
CustomThreadPoolExecutor customThreadPoolExecutor,
76-
DisposableLSPStateService disposableLSPStateService,
77-
CopybookNameService copybookNameService,
78-
Keywords keywords,
79-
MessageService messageService) {
70+
TextDocumentService textService,
71+
WorkspaceService workspaceService,
72+
WatcherService watchingService,
73+
SettingsService settingsService,
74+
LocaleStore localeStore,
75+
CustomThreadPoolExecutor customThreadPoolExecutor,
76+
DisposableLSPStateService disposableLSPStateService,
77+
CopybookNameService copybookNameService,
78+
Keywords keywords,
79+
MessageService messageService) {
8080
this.textService = textService;
8181
this.workspaceService = workspaceService;
8282
this.watchingService = watchingService;
@@ -128,7 +128,7 @@ public CompletableFuture<InitializeResult> initialize(@NonNull InitializeParams
128128
WorkspaceFoldersOptions workspaceFoldersOptions = new WorkspaceFoldersOptions();
129129
workspaceFoldersOptions.setSupported(TRUE);
130130
WorkspaceServerCapabilities workspaceServiceCapabilities =
131-
new WorkspaceServerCapabilities(workspaceFoldersOptions);
131+
new WorkspaceServerCapabilities(workspaceFoldersOptions);
132132
capabilities.setWorkspace(workspaceServiceCapabilities);
133133

134134
return supplyAsync(() -> new InitializeResult(capabilities));
@@ -153,19 +153,19 @@ public void initialized(@Nullable InitializedParams params) {
153153

154154
private void notifyConfiguredCopybookExtensions() {
155155
settingsService
156-
.fetchTextConfiguration(CPY_EXTENSIONS.label)
157-
.thenAccept(
158-
config -> {
159-
if (textService instanceof CobolTextDocumentService) {
160-
((CobolTextDocumentService) textService).notifyExtensionConfig(config);
161-
}
162-
});
156+
.fetchTextConfiguration(CPY_EXTENSIONS.label)
157+
.thenAccept(
158+
config -> {
159+
if (textService instanceof CobolTextDocumentService) {
160+
((CobolTextDocumentService) textService).notifyExtensionConfig(config);
161+
}
162+
});
163163
}
164164

165165
private void getLogLevelFromClient() {
166166
settingsService
167-
.fetchConfiguration(LOGGING_LEVEL.label)
168-
.thenAccept(LogLevelUtils.updateLogLevel());
167+
.fetchConfiguration(LOGGING_LEVEL.label)
168+
.thenAccept(LogLevelUtils.updateLogLevel());
169169
}
170170

171171
private void getLocaleFromClient() {
@@ -223,7 +223,9 @@ private ExecuteCommandOptions collectExecuteCommandList() {
223223
return new ExecuteCommandOptions(ImmutableList.of(ErrorCodes.MISSING_COPYBOOK.getLabel()));
224224
}
225225

226-
/** Represents the JSON RPC response structure for shutdown command as per LSP specification */
226+
/**
227+
* Represents the JSON RPC response structure for shutdown command as per LSP specification
228+
*/
227229
@AllArgsConstructor
228230
private static class ShutdownResponse {
229231
private final String result;

server/engine/src/test/java/org/eclipse/lsp/cobol/service/CobolLanguageServerTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private void prepareSettingsService(SettingsService settingsService, LocaleStore
145145
}
146146

147147
@Test
148-
void initializedConfig() {
148+
void initializedConfig() throws ExecutionException, InterruptedException {
149149
SettingsService settingsService = mock(SettingsServiceImpl.class);
150150
WatcherService watchingService = mock(WatcherService.class);
151151
LocaleStore localeStore = mock(LocaleStore.class);
@@ -157,8 +157,8 @@ void initializedConfig() {
157157
DialectService dialectService = mock(DialectService.class);
158158
when(dialectService.getSettingsSections()).thenReturn(ImmutableList.of("daco"));
159159

160-
when(settingsService.fetchTextConfiguration(anyString()))
161-
.thenReturn(CompletableFuture.supplyAsync(ImmutableList::of));
160+
CompletableFuture<List<String>> completableFuture = CompletableFuture.supplyAsync(ImmutableList::of);
161+
when(settingsService.fetchTextConfiguration(anyString())).thenReturn(completableFuture);
162162
prepareSettingsService(settingsService, localeStore);
163163

164164
CobolLanguageServer server =
@@ -175,6 +175,7 @@ void initializedConfig() {
175175
messageService);
176176

177177
server.initialized(new InitializedParams());
178+
completableFuture.get();
178179
verify(textService, times(1)).notifyExtensionConfig(any());
179180
}
180181

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2023 Broadcom.
3+
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
4+
*
5+
* This program and the accompanying materials are made
6+
* available under the terms of the Eclipse Public License 2.0
7+
* which is available at https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Broadcom, Inc. - initial API and implementation
13+
*
14+
*/
15+
package org.eclipse.lsp.cobol.usecases.variables;
16+
17+
import com.google.common.collect.ImmutableList;
18+
import com.google.common.collect.ImmutableMap;
19+
import org.eclipse.lsp.cobol.test.engine.UseCaseEngine;
20+
import org.junit.jupiter.api.Test;
21+
22+
/**
23+
* Occurs unbounded should not cause an error.
24+
*/
25+
class TestUnboundedOccurs {
26+
27+
private static final String TEXT = " IDENTIFICATION DIVISION.\n"
28+
+ " PROGRAM-ID. Subscripts.\n"
29+
+ " DATA DIVISION.\n"
30+
+ " LINKAGE SECTION.\n"
31+
+ " 01 {$*tab3}.\n"
32+
+ " 05 {$*oc1} occurs unbounded.\n"
33+
+ " 10 {$*item} PIC X.";
34+
35+
@Test
36+
void test() {
37+
UseCaseEngine.runTest(TEXT, ImmutableList.of(), ImmutableMap.of());
38+
}
39+
}

server/parser/src/main/antlr4/org/eclipse/lsp/cobol/core/parser/CobolParser.g4

+1-1
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ dataJustifiedClause
825825
;
826826

827827
dataOccursClause
828-
: OCCURS integerLiteral dataOccursTo? TIMES? (DEPENDING ON? qualifiedDataName)? dataOccursSort* (INDEXED BY? LOCAL? indexName+)?
828+
: OCCURS (integerLiteral | UNBOUNDED) dataOccursTo? TIMES? (DEPENDING ON? qualifiedDataName)? dataOccursSort* (INDEXED BY? LOCAL? indexName+)?
829829
;
830830

831831
dataOccursTo

0 commit comments

Comments
 (0)