From 51600f8368e89e9e4aaea7c89af8313204ca47d1 Mon Sep 17 00:00:00 2001 From: Billy Ma Date: Thu, 3 Jun 2021 11:03:42 -0700 Subject: [PATCH] Handle URI Variation (#29) * Handle URI Variation * Clean up unused import --- .../slds/lsp/diagnostics/Diagnoser.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lsp/src/main/java/com/salesforce/slds/lsp/diagnostics/Diagnoser.java b/lsp/src/main/java/com/salesforce/slds/lsp/diagnostics/Diagnoser.java index 9dcd222..ad4c98a 100644 --- a/lsp/src/main/java/com/salesforce/slds/lsp/diagnostics/Diagnoser.java +++ b/lsp/src/main/java/com/salesforce/slds/lsp/diagnostics/Diagnoser.java @@ -12,9 +12,9 @@ import com.salesforce.slds.lsp.registries.DiagnosticResultRegistry; import com.salesforce.slds.lsp.registries.TextDocumentRegistry; import com.salesforce.slds.lsp.services.interfaces.StateService; -import com.salesforce.slds.validation.aggregators.SimpleAggregator; import com.salesforce.slds.shared.models.core.Bundle; import com.salesforce.slds.shared.models.core.Entry; +import com.salesforce.slds.validation.aggregators.SimpleAggregator; import com.salesforce.slds.validation.processors.SortAndFilterProcessor; import com.salesforce.slds.validation.runners.ValidateRunner; import com.salesforce.slds.validation.validators.interfaces.Validator; @@ -65,8 +65,17 @@ public void diagnose(TextDocumentItem item) { runner.run(); + /** + * Handles URI variation between different FileSystem format. + * `file:///c%3A/...` - Windows OS + * `file:/c:/...` - Windows OS + * `file:///...` - Mac OS + * `file:/...` - Mac OS + */ + File itemFile = new File(URI.create(item.getUri()).getPath()); + Optional result = bundle.getEntries().stream() - .filter(entry -> entry.getPath().equalsIgnoreCase(item.getUri())).findFirst(); + .filter(entry -> new File(URI.create(entry.getPath()).getPath()).equals(itemFile)).findFirst(); List diagnostics = converter.convert(result.get()); diagnosticRegistry.put(item.getUri(), diagnostics); @@ -97,7 +106,7 @@ public Bundle getBundle(TextDocumentItem entry) throws IOException { if (item != null) { bundle.getEntries().add(createEntry(item)); } else { - bundle.getEntries().add(createEntry( f.toURI().toString(), Files.readAllLines(f.toPath()))); + bundle.getEntries().add(createEntry(f.toURI().toString(), Files.readAllLines(f.toPath()))); } } }