-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support of 'classpath:' prefix in spring.config.imports property
See: #536
- Loading branch information
Showing
14 changed files
with
782 additions
and
43 deletions.
There are no files selected for viewing
120 changes: 120 additions & 0 deletions
120
...ain/java/org/springframework/ide/vscode/boot/app/ClasspathResourceCompletionProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 Pivotal, Inc. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Pivotal, Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.springframework.ide.vscode.boot.app; | ||
|
||
import static org.springframework.ide.vscode.boot.common.CommonLanguageTools.getValueType; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.ide.vscode.boot.common.PropertyCompletionFactory; | ||
import org.springframework.ide.vscode.boot.java.value.ValuePropertyKeyProposal; | ||
import org.springframework.ide.vscode.boot.metadata.CachingValueProvider; | ||
import org.springframework.ide.vscode.boot.metadata.PropertyInfo; | ||
import org.springframework.ide.vscode.boot.metadata.SpringPropertyIndexProvider; | ||
import org.springframework.ide.vscode.boot.metadata.ValueProviderRegistry; | ||
import org.springframework.ide.vscode.boot.metadata.hints.StsValueHint; | ||
import org.springframework.ide.vscode.boot.metadata.hints.ValueHintHoverInfo; | ||
import org.springframework.ide.vscode.commons.java.IClasspathUtil; | ||
import org.springframework.ide.vscode.commons.java.IJavaProject; | ||
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits; | ||
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionEngine; | ||
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal; | ||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder; | ||
import org.springframework.ide.vscode.commons.languageserver.util.LanguageSpecific; | ||
import org.springframework.ide.vscode.commons.languageserver.util.PrefixFinder; | ||
import org.springframework.ide.vscode.commons.util.BadLocationException; | ||
import org.springframework.ide.vscode.commons.util.FuzzyMatcher; | ||
import org.springframework.ide.vscode.commons.util.FuzzyMap.Match; | ||
import org.springframework.ide.vscode.commons.util.text.LanguageId; | ||
import org.springframework.ide.vscode.commons.util.text.TextDocument; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
import reactor.core.publisher.Flux; | ||
|
||
@Component | ||
public class ClasspathResourceCompletionProvider implements ICompletionEngine, LanguageSpecific { | ||
|
||
private static String[] CLASSPATH_PREFIXES = { | ||
"classpath:", | ||
"classpath*:" | ||
}; | ||
|
||
private static PrefixFinder PREFIX_FINDER = new PrefixFinder() { | ||
@Override | ||
protected boolean isPrefixChar(char c) { | ||
return Character.isJavaIdentifierPart(c) || c=='-' || c=='.' || c=='/' || c==':' || c=='*'; | ||
} | ||
}; | ||
private static final Collection<LanguageId> LANGUAGES = ImmutableList.of( | ||
LanguageId.BOOT_PROPERTIES, | ||
LanguageId.BOOT_PROPERTIES_YAML | ||
); | ||
|
||
@Autowired JavaProjectFinder projectFinder; | ||
|
||
public ClasspathResourceCompletionProvider(BootLanguageServerParams params) { | ||
} | ||
|
||
private static class ClasspathHints extends CachingValueProvider { | ||
@Override | ||
protected Flux<StsValueHint> getValuesAsync(IJavaProject javaProject, String query) { | ||
return Flux.fromStream( | ||
IClasspathUtil.getClasspathResources(javaProject.getClasspath()).stream() | ||
.distinct().map(r -> r.replaceAll("\\\\", "/")) | ||
.map(StsValueHint::create) | ||
); | ||
} | ||
} | ||
|
||
private ClasspathHints classpathHints = new ClasspathHints(); | ||
private PropertyCompletionFactory completionFactory = new PropertyCompletionFactory(); | ||
|
||
@Override | ||
public Collection<ICompletionProposal> getCompletions(TextDocument doc, int offset) { | ||
ImmutableList.Builder<ICompletionProposal> proposals = ImmutableList.builder(); | ||
IJavaProject jp = projectFinder.find(doc.getId()).orElse(null); | ||
if (jp!=null) { | ||
String prefix = PREFIX_FINDER.getPrefix(doc, offset); | ||
for (String CLASSPATH : CLASSPATH_PREFIXES) { | ||
if (prefix.startsWith(CLASSPATH)) { | ||
String query = prefix.substring(CLASSPATH.length()); | ||
Flux<StsValueHint> valueHints = classpathHints.getValues(jp, query); | ||
valueHints.toStream().forEach(hint -> { | ||
String valueCandidate = hint.getValue(); | ||
int startOfValue = offset - query.length(); | ||
double score = FuzzyMatcher.matchScore(query, valueCandidate); | ||
if (score != 0) { | ||
DocumentEdits edits = new DocumentEdits(doc, false); | ||
edits.delete(startOfValue, offset); | ||
edits.insert(offset, valueCandidate); | ||
proposals.add(completionFactory.valueProposal(valueCandidate, query, "String", | ||
score, edits, ValueHintHoverInfo.create(hint)) | ||
); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
return proposals.build(); | ||
} | ||
|
||
@Override | ||
public Collection<LanguageId> supportedLanguages() { | ||
return LANGUAGES; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
.../spring-boot-language-server/src/test/resources/test-projects/demo-conf-import/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
HELP.md | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ |
Binary file added
BIN
+57.4 KB
...e-server/src/test/resources/test-projects/demo-conf-import/.mvn/wrapper/maven-wrapper.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions
2
...r/src/test/resources/test-projects/demo-conf-import/.mvn/wrapper/maven-wrapper.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip | ||
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar |
Oops, something went wrong.