use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.
the class N4JSTextDocumentFrontend method implementation.
@Override
protected Either<List<? extends Location>, List<? extends LocationLink>> implementation(ResourceTaskContext rtc, ImplementationParams params, CancelIndicator cancelIndicator) {
URI uri = rtc.getURI();
N4JSProjectConfigSnapshot project = workspaceAccess.findProjectContaining(rtc.getResource());
String targetFileName = resourceNameComputer.generateFileDescriptor(rtc.getResource(), uri, JS_FILE_EXTENSION);
List<Location> locations = new ArrayList<>();
if (project != null && !Strings.isNullOrEmpty(targetFileName)) {
String outputPath = project.getOutputPath();
Path projectLocation = project.getPathAsFileURI().toFileSystemPath();
Path genFilePath = projectLocation.resolve(outputPath + "/" + targetFileName);
Range range = findRange(params, genFilePath);
Location location = new Location();
location.setUri(new FileURI(genFilePath.toFile()).toString());
location.setRange(range);
locations.add(location);
}
return Either.forLeft(locations);
}
use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.
the class RepoRelativePathHolder method get.
/**
* The method returns the RepoRelativePath for a given SyntaxRelatedTElement. It caches the result for subsequent
* queries.
*/
public RepoRelativePath get(IdentifiableElement idElement) {
Resource res = evadeStaticPolyfillResource(idElement);
if (res != null) {
if (!modulesToRepoCache.containsKey(res)) {
FileURI fileURI = new FileURI(fixupURI(res));
RepoRelativePath rrpRes = RepoRelativePath.compute(fileURI, workspaceAccess, res);
if (rrpRes != null) {
modulesToRepoCache.put(res, rrpRes);
}
}
RepoRelativePath rrpRes = modulesToRepoCache.get(res);
if (rrpRes != null && idElement instanceof SyntaxRelatedTElement) {
return rrpRes.withLine((SyntaxRelatedTElement) idElement);
}
}
return null;
}
use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.
the class FindArtifactHelper method findArtifact.
/**
* If the receiving source folder actually contains a file for the given fully qualified name and file extension on
* disk, this method will return a URI for this file of the same format as the URIs returned by method
* {@link N4JSSourceFolderSnapshot#getContents()}. Otherwise, this method returns <code>null</code>.
* <p>
* The file extension may but need not contain a leading '.'.
* <p>
* Implementations are expected to be optimized for fast look-up (in particular, they should avoid iterating over
* all URIs returned by method {@link N4JSSourceFolderSnapshot#getContents()}).
*/
public FileURI findArtifact(N4JSSourceFolderSnapshot sourceFolder, QualifiedName name, Optional<String> fileExtension) {
final List<String> nameSegments = name.getSegments();
if (nameSegments.isEmpty()) {
return null;
}
final String[] nameSegmentsCpy = nameSegments.toArray(new String[nameSegments.size()]);
final String ext = fileExtension.or("").trim();
final String extWithDot = !ext.isEmpty() && !ext.startsWith(".") ? "." + ext : ext;
final int idxLast = nameSegmentsCpy.length - 1;
nameSegmentsCpy[idxLast] = nameSegmentsCpy[idxLast] + extWithDot;
FileURI sourceFolderPath = sourceFolder.getPathAsFileURI();
FileURI result = sourceFolderPath.appendSegments(nameSegmentsCpy);
if (result.exists()) {
return result;
}
return null;
}
use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.
the class N4JSWorkspaceConfig method reloadAllProjectInformationFromDisk.
/**
* Clears this workspace and re-initializes it by searching the file system for projects.
*/
protected void reloadAllProjectInformationFromDisk() {
deregisterAllProjects();
Path baseDir = getPathAsFileURI().toPath();
Map<Path, ProjectDescription> projects = projectDiscoveryHelper.collectAllProjectDirs(Collections.singleton(baseDir));
for (Path newProjectPath : projects.keySet()) {
FileURI newProjectPathAsFileURI = new FileURI(newProjectPath);
ProjectDescription pd = projects.get(newProjectPath);
registerProject(newProjectPathAsFileURI, pd);
}
}
use of org.eclipse.n4js.workspace.locations.FileURI in project n4js by eclipse.
the class IdeTestLanguageClient method publishDiagnostics.
@Override
public void publishDiagnostics(PublishDiagnosticsParams diagnostics) {
URI uriRaw = URI.createURI(diagnostics.getUri());
if (N4Scheme.isN4Scheme(uriRaw)) {
return;
}
if (!uriRaw.isFile()) {
throw new IllegalArgumentException("not a file URI: " + uriRaw);
}
FileURI uri = new FileURI(uriRaw);
issues.removeAll(uri);
errors.removeAll(uri);
warnings.removeAll(uri);
List<Diagnostic> issueList = diagnostics.getDiagnostics();
if (issueList.isEmpty()) {
return;
}
for (Diagnostic diag : issueList) {
issues.put(uri, diag);
switch(diag.getSeverity()) {
case Error:
errors.put(uri, diag);
break;
case Warning:
warnings.put(uri, diag);
break;
default:
// ignore
break;
}
}
}
Aggregations