Spring Boot Language Server in Eclipse accepts both .yml and .yaml

This commit is contained in:
Kris De Volder
2019-01-31 15:23:54 -08:00
parent 78f6380e21
commit 2a83e31172
3 changed files with 41 additions and 21 deletions

View File

@@ -51,8 +51,8 @@
</content-type>
<file-association
content-type="org.springframework.boot.ide.properties.application.yml"
file-names="application.yml,bootstrap.yml,application-dev.yml"
file-patterns="application-*.yml">
file-names="application.yml,bootstrap.yml,application-dev.yml,application.yaml,bootstrap.yaml,application-dev.yaml"
file-patterns="application-*.yml,application-*.yaml">
</file-association>
</extension>

View File

@@ -35,6 +35,7 @@ import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.WorkspaceFolder;
import org.springframework.ide.vscode.boot.java.handlers.ReferenceProvider;
import org.springframework.ide.vscode.boot.properties.BootPropertiesLanguageServerComponents;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
import org.springframework.ide.vscode.commons.util.BadLocationException;
import org.springframework.ide.vscode.commons.util.text.TextDocument;
@@ -132,23 +133,30 @@ public class ValuePropertyReferencesProvider implements ReferenceProvider {
}
private boolean isPropertiesFile(Path path) {
Path fileName = path.getFileName();
String fileName = path.getFileName().toString();
if (fileName.toString().endsWith(".properties") || path.toString().endsWith(".yml")) {
return fileName.toString().contains("application");
}
else {
return false;
if (fileName.endsWith(BootPropertiesLanguageServerComponents.PROPERTIES)) {
return fileName.contains("application");
} else {
for (String yml : BootPropertiesLanguageServerComponents.YML) {
if (fileName.endsWith(yml)) {
return fileName.contains("application");
}
}
}
return false;
}
private List<Location> findReferences(Path path, String propertyKey) {
String filePath = path.toString();
if (filePath.endsWith(".properties")) {
if (filePath.endsWith(BootPropertiesLanguageServerComponents.PROPERTIES)) {
return findReferencesInPropertiesFile(filePath, propertyKey);
}
else if (filePath.endsWith(".yml")) {
return findReferencesInYMLFile(filePath, propertyKey);
} else {
for (String yml : BootPropertiesLanguageServerComponents.YML) {
if (filePath.endsWith(yml)) {
return findReferencesInYMLFile(filePath, propertyKey);
}
}
}
return new ArrayList<Location>();
}

View File

@@ -55,8 +55,8 @@ import com.google.common.collect.ImmutableSet;
*/
public class BootPropertiesLanguageServerComponents implements LanguageServerComponents {
private static final String YML = ".yml";
private static final String PROPERTIES = ".properties";
public static final String[] YML = {".yml", ".yaml" } ;
public static final String PROPERTIES = ".properties";
private static final Set<LanguageId> LANGUAGES = ImmutableSet.of(
LanguageId.BOOT_PROPERTIES,
@@ -135,8 +135,12 @@ public class BootPropertiesLanguageServerComponents implements LanguageServerCom
if (uri!=null) {
if (uri.endsWith(PROPERTIES)) {
return propertiesCompletions.getCompletions(document, offset);
} else if (uri.endsWith(YML)) {
return yamlCompletions.getCompletions(document, offset);
} else {
for (String yml : YML) {
if (uri.endsWith(yml)) {
return yamlCompletions.getCompletions(document, offset);
}
}
}
}
return ImmutableList.of();
@@ -153,8 +157,12 @@ public class BootPropertiesLanguageServerComponents implements LanguageServerCom
if (uri!=null) {
if (uri.endsWith(PROPERTIES)) {
return propertiesHovers.getHoverInfo(document, offset);
} else if (uri.endsWith(YML)) {
return ymlHovers.getHoverInfo(document, offset);
} else {
for (String yml : YML) {
if (uri.endsWith(yml)) {
return ymlHovers.getHoverInfo(document, offset);
}
}
}
}
return null;
@@ -170,9 +178,13 @@ public class BootPropertiesLanguageServerComponents implements LanguageServerCom
if (uri.endsWith(PROPERTIES)) {
propertiesReconciler.reconcile(doc, problemCollector);
return;
} else if (uri.endsWith(YML)) {
ymlReconciler.reconcile(doc, problemCollector);
return;
} else {
for (String yml : YML) {
if (uri.endsWith(yml)) {
ymlReconciler.reconcile(doc, problemCollector);
return;
}
}
}
}
//No real reconciler is applicable. So tell the problemCollector there are no problems.