use of org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot 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.N4JSProjectConfigSnapshot in project n4js by eclipse.
the class N4JSCodeActionService method applyToProject.
/**
* Applies all fixes of the same kind to the project containing the given URI.
*/
public WorkspaceEdit applyToProject(URI uri, String issueCode, String fixId, CancelIndicator cancelIndicator) {
WorkspaceEdit result = new WorkspaceEdit();
QuickFixImplementation quickfix = findOriginatingQuickfix(issueCode, fixId);
if (quickfix == null) {
return result;
}
N4JSWorkspaceConfigSnapshot wc = (N4JSWorkspaceConfigSnapshot) concurrentIndex.getWorkspaceConfigSnapshot();
N4JSProjectConfigSnapshot project = wc.findProjectContaining(uri);
if (project == null) {
return result;
}
List<URI> urisInProject = Lists.newArrayList(IterableExtensions.flatMap(project.getSourceFolders(), N4JSSourceFolderSnapshot::getContents));
Map<String, List<TextEdit>> allEdits = new HashMap<>();
for (URI currURI : urisInProject) {
Map<String, List<TextEdit>> edits = doApplyToFile(currURI, issueCode, quickfix, cancelIndicator);
allEdits.putAll(edits);
}
result.setChanges(allEdits);
return result;
}
use of org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot in project n4js by eclipse.
the class N4JSDReader method readN4JSDs.
/**
* Reads all N4JSD files in project, scans for types and links the tests.
*
* @return all types in a mapped with fully qualified type name (inclusive module spec) as key, the type info only
* contains the types, no other information yet.
* @throws InterruptedException
* thrown when user cancels the operation
*/
public Collection<SpecInfo> readN4JSDs(Collection<N4JSProjectConfigSnapshot> projects, Function<N4JSProjectConfigSnapshot, ResourceSet> resSetProvider, SubMonitorMsg monitor) throws InterruptedException {
SpecInfosByName specInfosByName = new SpecInfosByName(issueAcceptor, globalScopeProvider, containerTypesHelper, workspaceAccess);
ResourceSet resSet = null;
SubMonitorMsg sub = monitor.convert(2 * 100 * projects.size());
for (N4JSProjectConfigSnapshot project : projects) {
if (resSet == null) {
resSet = resSetProvider.apply(project);
}
readScripts(specInfosByName, project, resSet, sub.newChild(100));
}
for (N4JSProjectConfigSnapshot project : projects) {
if (resSet == null) {
resSet = resSetProvider.apply(project);
}
linkTests(specInfosByName, project, resSet, sub.newChild(100));
}
return specInfosByName.values();
}
use of org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot in project n4js by eclipse.
the class JSONIdeContentProposalProvider method proposeVersions.
private void proposeVersions(ContentAssistContext context, IIdeContentProposalAcceptor acceptor, List<String> namePath) {
if (namePath.size() >= 2) {
// somewhat poor heuristic: propose all projects that are known in the current workspace
String devOrDep = namePath.get(namePath.size() - 2);
if (PackageJsonProperties.DEPENDENCIES.name.equals(devOrDep) || PackageJsonProperties.DEV_DEPENDENCIES.name.equals(devOrDep)) {
NameValuePair pair = (NameValuePair) context.getCurrentModel();
N4JSProjectConfigSnapshot project = workspaceAccess.findProjectByName(context.getResource(), pair.getName());
if (project != null) {
VersionNumber version = project.getVersion();
ContentAssistEntry versionEntry = getProposalCreator().createProposal('"' + version.toString() + '"', context, ContentAssistEntry.KIND_VALUE, null);
acceptor.accept(versionEntry, getProposalPriorities().getDefaultPriority(versionEntry));
}
ContentAssistEntry wildcard = getProposalCreator().createProposal("\"*\"", context, ContentAssistEntry.KIND_VALUE, null);
acceptor.accept(wildcard, getProposalPriorities().getDefaultPriority(wildcard));
}
}
}
use of org.eclipse.n4js.workspace.N4JSProjectConfigSnapshot in project n4js by eclipse.
the class DtsSubGenerator method isActive.
@Override
public boolean isActive(Resource input) {
boolean superIsActive = super.isActive(input);
if (!superIsActive) {
return false;
}
N4JSWorkspaceConfigSnapshot ws = workspaceAccess.getWorkspaceConfig(input);
N4JSProjectConfigSnapshot project = ws.findProjectContaining(input.getURI());
if (project != null) {
ProjectDescription pd = project.getProjectDescription();
return N4JSLanguageUtils.isDtsGenerationActive(pd);
}
return false;
}
Aggregations