Skip to content

Commit

Permalink
feature(FUSETOOLS2-1417): Completion for Twitter lang values (ISO_639-1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Delawen committed Sep 12, 2023
1 parent fb97ef3 commit 26aecf3
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package com.github.cameltooling.lsp.internal.completion;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -76,6 +78,16 @@ public List<CompletionItem> apply(CamelCatalog camelCatalog) {
} catch (ApiException e) {
LOGGER.error("Error while trying to provide completion for Kubernetes connected mode", e);
}
} else if("lang".equalsIgnoreCase(endpointOptionModel.getName())
&& optionParamValueURIInstance.getComponentName().startsWith("twitter-")) {
List<CompletionItem> items = new ArrayList<>();
//We will just rely on Java to be updated for this
for(String lang : Locale.getISOLanguages()) {
CompletionItem langItem = new CompletionItem(lang);
CompletionResolverUtils.applyTextEditToCompletionItem(optionParamValueURIInstance, langItem);
items.add(langItem);
}
return items;
}
}
return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.cameltooling.lsp.internal.completion;

import com.github.cameltooling.lsp.internal.AbstractCamelLanguageServerTest;
import com.github.cameltooling.lsp.internal.CamelLanguageServer;
import org.eclipse.lsp4j.CompletionItem;
import org.eclipse.lsp4j.Position;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Locale;

import static com.github.cameltooling.lsp.internal.util.RouteTextBuilder.createXMLBlueprintRoute;
import static org.assertj.core.api.Assertions.assertThat;

class TwitterTimelineCompletionTest extends AbstractCamelLanguageServerTest {

@Test
void testTwitterTimelineCompletionForLang() throws Exception {
CamelLanguageServer languageServer =
initializeLanguageServer(createXMLBlueprintRoute("twitter-timeline:HOME?lang="), ".xml");
List<CompletionItem> completions =
getCompletionFor(languageServer, new Position(0, 38)).get().getLeft();

// It should return the full list of ISO_639-1
// which is the two-letter codes for languages
assertThat(completions)
.isNotEmpty()
//We will just rely on Java to be updated for this
.hasSize(Locale.getISOLanguages().length)
.allMatch(item -> item.getLabel().length() == 2);
}
}

0 comments on commit 26aecf3

Please sign in to comment.