Skip to content

Commit

Permalink
Handle URI Variation (#29)
Browse files Browse the repository at this point in the history
* Handle URI Variation

* Clean up unused import
  • Loading branch information
billyma authored Jun 3, 2021
1 parent eb4cf85 commit 51600f8
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Entry> 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<DiagnosticResult> diagnostics = converter.convert(result.get());
diagnosticRegistry.put(item.getUri(), diagnostics);
Expand Down Expand Up @@ -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())));
}
}
}
Expand Down

0 comments on commit 51600f8

Please sign in to comment.