From 8e3fa7b8d2ed53e794218a0d9f38f35b48559bfc Mon Sep 17 00:00:00 2001 From: hans <837713748@qq.com> Date: Wed, 13 Sep 2023 21:34:46 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E5=A4=8Dproperties=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=8F=90=E7=A4=BAbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + .../PropertiesCompletionProvider.java | 1 + .../service/SuggestionServiceImpl.java | 42 +++++++++++++------ 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4db0d5..e8f90da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Added - Initializer ux logic optimization - Removing Pulling Metadata Popup +- [fix] app.properties code hint bug ## [0.0.1-M6] ### Added diff --git a/src/main/java/org/noear/solon/idea/plugin/suggestion/completion/PropertiesCompletionProvider.java b/src/main/java/org/noear/solon/idea/plugin/suggestion/completion/PropertiesCompletionProvider.java index ede6224..e7cf1db 100644 --- a/src/main/java/org/noear/solon/idea/plugin/suggestion/completion/PropertiesCompletionProvider.java +++ b/src/main/java/org/noear/solon/idea/plugin/suggestion/completion/PropertiesCompletionProvider.java @@ -43,6 +43,7 @@ public class PropertiesCompletionProvider extends CompletionProvider propertiesSearchIndex; private final Trie hintsSearchIndex; @@ -41,7 +46,7 @@ public class SuggestionServiceImpl implements SuggestionService{ this.hintsSearchIndex = new PatriciaTrie<>(); } - private void clearSearchIndex(){ + private void clearSearchIndex() { this.propertiesSearchIndex.clear(); this.hintsSearchIndex.clear(); } @@ -101,7 +106,6 @@ public class SuggestionServiceImpl implements SuggestionService{ } - private void loadModuleSearchIndex(Module module) { /** * Order entries include SDK, libraries and other modules the module uses. @@ -118,10 +122,10 @@ public class SuggestionServiceImpl implements SuggestionService{ private void processContainers(Module module, List containersToProcess) { for (MetadataContainer metadataContainer : containersToProcess) { String metadataFilePath = metadataContainer.getFileUrl(); - try (InputStream inputStream = metadataContainer.getMetadataFile().getInputStream()){ + try (InputStream inputStream = metadataContainer.getMetadataFile().getInputStream()) { SolonConfigurationMetadata solonConfigurationMetadata = JSON.parseObject(new BufferedReader(new InputStreamReader(inputStream)), SolonConfigurationMetadata.class); buildMetadataHierarchy(module, solonConfigurationMetadata); - }catch (IOException e){ + } catch (IOException e) { LoggerUtil.getLogger(this.getClass()).error("Exception encountered while processing metadata file: " + metadataFilePath, e); } } @@ -161,7 +165,19 @@ public class SuggestionServiceImpl implements SuggestionService{ SortedMap sortedMap = this.propertiesSearchIndex.prefixMap(queryWithDotDelimitedPrefixes); List builders = new ArrayList<>(); for (Map.Entry entry : sortedMap.entrySet()) { - builders.add(toLookupElementBuilder(entry.getValue())); + builders.add(toLookupElementBuilder(entry.getValue()).withInsertHandler((context, item) -> { + int index = queryWithDotDelimitedPrefixes.lastIndexOf("."); + Editor editor = context.getEditor(); + int startOffset = context.getStartOffset(); + int endOffset = context.getTailOffset(); + Document document = editor.getDocument(); + String text = item.getLookupString(); + if (index > 0) { + text = text.substring(index + 1); + } + document.replaceString(startOffset, endOffset, text); + editor.getCaretModel().moveToOffset(endOffset); + })); } return builders; } @@ -169,12 +185,14 @@ public class SuggestionServiceImpl implements SuggestionService{ @Override public @Nullable List findHintSuggestionsForQueryPrefix(String property, String queryWithDotDelimitedPrefixes) { SolonConfigurationMetadataHint hint = this.hintsSearchIndex.get(property); - if (hint == null){ + if (hint == null) { return new ArrayList<>(); } List builders = new ArrayList<>(); for (SolonConfigurationMetadataHintValue hintValue : hint.getValues()) { - if (hintValue.getValue() == null) {continue;} + if (hintValue.getValue() == null) { + continue; + } builders.add(toLookupElementBuilder(hintValue)); } return builders; @@ -182,11 +200,11 @@ public class SuggestionServiceImpl implements SuggestionService{ private LookupElementBuilder toLookupElementBuilder(SolonConfigurationMetadataHintValue hintValue) { LookupElementBuilder builder = LookupElementBuilder.create(hintValue.getValue()); - if (hintValue.getDescription() != null){ + if (hintValue.getDescription() != null) { builder.withTypeText(hintValue.getDescription(), true); } SolonConfigurationMetadataProperty property = this.propertiesSearchIndex.get(hintValue.getValue()); - if (property != null && property.getDefaultValue() != null){ + if (property != null && property.getDefaultValue() != null) { if (hintValue.getValue().toString().equals(property.getDefaultValue().toString())) { builder.bold(); } @@ -196,8 +214,8 @@ public class SuggestionServiceImpl implements SuggestionService{ private LookupElementBuilder toLookupElementBuilder(SolonConfigurationMetadataProperty property) { LookupElementBuilder builder = LookupElementBuilder.create(property.getName()); - if (property.getDescription() != null){ - builder.withTypeText(property.getDescription(),true); + if (property.getDescription() != null) { + builder.withTypeText(property.getDescription(), true); } return builder; } -- Gitee