Java Code Examples for org.eclipse.lsp4j.WorkspaceFolder

The following examples show how to use org.eclipse.lsp4j.WorkspaceFolder. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: vscode-as3mxml   Source File: WorkspaceFolderManager.java    License: Apache License 2.0 6 votes vote down vote up
public WorkspaceFolderData setFallbackFolderData(WorkspaceFolder folder, IProjectConfigStrategy config)
{
    if(fallbackFolderData != null)
    {
        if(fallbackFolderData.folder.equals(folder)
                && fallbackFolderData.config.equals(config))
        {
            return fallbackFolderData;
        }
        fallbackFolderData.cleanup();
        fallbackFolderData = null;
    }
    WorkspaceFolderData folderData = new WorkspaceFolderData(folder, config);
    fallbackFolderData = folderData;
    return fallbackFolderData;
}
 
Example 2
Source Project: vscode-as3mxml   Source File: ActionScriptServices.java    License: Apache License 2.0 6 votes vote down vote up
public void addWorkspaceFolder(WorkspaceFolder folder)
{
    IProjectConfigStrategy config = projectConfigStrategyFactory.create(folder);
    WorkspaceFolderData folderData = workspaceFolderManager.addWorkspaceFolder(folder, config);
    folderData.codeProblemTracker.setLanguageClient(languageClient);
    folderData.configProblemTracker.setLanguageClient(languageClient);
    
    //let's get the code intelligence up and running!
    Path path = getMainCompilationUnitPath(folderData);
    if (path != null)
    {
        String normalizedPath = FilenameNormalization.normalize(path.toAbsolutePath().toString());
        IFileSpecification fileSpec = fileTracker.getFileSpecification(normalizedPath);
        compilerWorkspace.fileChanged(fileSpec);
    }

    checkProjectForProblems(folderData);
}
 
Example 3
Source Project: vscode-as3mxml   Source File: ActionScriptServices.java    License: Apache License 2.0 6 votes vote down vote up
private void updateFallbackWorkspaceFolder()
{
    if(oldFrameworkSDKPath == null)
    {
        return;
    }
    WorkspaceFolder folder = new WorkspaceFolder(Paths.get(oldFrameworkSDKPath).toUri().toString());
    fallbackConfig = new SimpleProjectConfigStrategy(folder);
    WorkspaceFolderData fallbackFolderData = workspaceFolderManager.setFallbackFolderData(folder, fallbackConfig);
    for(Path openFilePath : fileTracker.getOpenFiles())
    {
        WorkspaceFolderData folderData = workspaceFolderManager.getWorkspaceFolderDataForSourceFile(openFilePath);
        if(fallbackFolderData.equals(folderData))
        {
            fallbackConfig.didOpen(openFilePath);
        }
    }
}
 
Example 4
Source Project: intellij-quarkus   Source File: LSPIJUtils.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Nonnull
public static WorkspaceFolder toWorkspaceFolder(@Nonnull Module project) {
    WorkspaceFolder folder = new WorkspaceFolder();
    folder.setUri(toUri(project).toString());
    folder.setName(project.getName());
    return folder;
}
 
Example 5
@Override
public CompletableFuture<List<WorkspaceFolder>> workspaceFolders() {
    List<WorkspaceFolder> res = new ArrayList<>(wrapper.allWatchedProjects.size());
    for (final Module project : wrapper.allWatchedProjects) {
        res.add(LSPIJUtils.toWorkspaceFolder(project));
    }
    return CompletableFuture.completedFuture(res);
}
 
Example 6
Source Project: MSPaintIDE   Source File: DefaultLanguageServerWrapper.java    License: MIT License 5 votes vote down vote up
public DefaultLanguageServerWrapper(StartupLogic startupLogic, LSP lsp, String serverPath, List<String> lspArgs, BiConsumer<LanguageServerWrapper, File> workspaceInit) {
    this.documentManager = new DefaultDocumentManager(this, startupLogic);
    this.startupLogic = startupLogic;
    this.fileWatchManager = startupLogic.getFileWatchManager();
    this.lsp = lsp;
    this.serverPath = () -> serverPath;
    this.lspArgs = lspArgs;
    this.workspaceInit = workspaceInit;

    if (!lsp.usesWorkspaces()) return;
    this.workspaces.addListener((ListChangeListener<WorkspaceFolder>) change -> {
        var added = new ArrayList<WorkspaceFolder>();
        var removed = new ArrayList<WorkspaceFolder>();

        while (change.next()) {
            added.addAll(change.getAddedSubList());
            removed.addAll(change.getRemoved());
        }

        LOGGER.info("Adding: {}  Removing: {}", added, removed);

        this.languageServer.getWorkspaceService().didChangeWorkspaceFolders(
                new DidChangeWorkspaceFoldersParams(
                        new WorkspaceFoldersChangeEvent(
                                added,
                                removed)));
    });
}
 
Example 7
public ASConfigProjectConfigStrategy(WorkspaceFolder workspaceFolder)
{
    this.workspaceFolder = workspaceFolder;

    Path workspacePath = Paths.get(URI.create(workspaceFolder.getUri()));
    asconfigPath = workspacePath.resolve(ASCONFIG_JSON);
}
 
Example 8
Source Project: vscode-as3mxml   Source File: WorkspaceFolderManager.java    License: Apache License 2.0 5 votes vote down vote up
public WorkspaceFolderData addWorkspaceFolder(WorkspaceFolder folder, IProjectConfigStrategy config)
{
    workspaceFolders.add(folder);
    WorkspaceFolderData folderData = new WorkspaceFolderData(folder, config);
    workspaceFolderToData.put(folder, folderData);
    return folderData;
}
 
Example 9
Source Project: vscode-as3mxml   Source File: WorkspaceFolderManager.java    License: Apache License 2.0 5 votes vote down vote up
public void removeWorkspaceFolder(WorkspaceFolder folder)
{
    if(!workspaceFolderToData.containsKey(folder))
    {
        return;
    }
    workspaceFolders.remove(folder);
    WorkspaceFolderData folderData = workspaceFolderToData.get(folder);
    workspaceFolderToData.remove(folder);
    folderData.cleanup();
}
 
Example 10
@Override
public void addProjectsForWorkspaceFolder(WorkspaceConfig workspaceConfig, WorkspaceFolder workspaceFolder,
		Set<String> existingNames) {
	if (workspaceFolder != null) {
		if (workspaceFolder.getUri() != null) {
			SourceFolderCustomImplTest.CustomFileProjectConfig project = new SourceFolderCustomImplTest.CustomFileProjectConfig(
					getUriExtensions().toUri(workspaceFolder.getUri()), workspaceConfig);
			project.addSourceFolder(".");
			workspaceConfig.addProject(project);
		}
	}
}
 
Example 11
Source Project: xtext-core   Source File: IndexOnlyProjectTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public com.google.inject.Module getServerModule() {
  ServerModule _serverModule = new ServerModule();
  final com.google.inject.Module _function = (Binder it) -> {
    AnnotatedBindingBuilder<IMultiRootWorkspaceConfigFactory> _bind = it.<IMultiRootWorkspaceConfigFactory>bind(IMultiRootWorkspaceConfigFactory.class);
    _bind.toInstance(new MultiRootWorkspaceConfigFactory() {
      @Override
      public void addProjectsForWorkspaceFolder(final WorkspaceConfig workspaceConfig, final WorkspaceFolder workspaceFolder, final Set<String> existingNames) {
        String _uri = null;
        if (workspaceFolder!=null) {
          _uri=workspaceFolder.getUri();
        }
        boolean _tripleNotEquals = (_uri != null);
        if (_tripleNotEquals) {
          URI _uri_1 = this.getUriExtensions().toUri(workspaceFolder.getUri());
          String _uniqueProjectName = this.getUniqueProjectName(workspaceFolder.getName(), existingNames);
          final FileProjectConfig project = new FileProjectConfig(_uri_1, _uniqueProjectName) {
            @Override
            public boolean isIndexOnly() {
              return true;
            }
          };
          project.addSourceFolder(".");
          workspaceConfig.addProject(project);
        }
      }
    });
  };
  return Modules2.mixin(_serverModule, _function);
}
 
Example 12
@Override
public IWorkspaceConfig getWorkspaceConfig(List<WorkspaceFolder> workspaceFolders) {
	WorkspaceConfig workspaceConfig = new WorkspaceConfig();
	Set<String> existingProjectNames = new HashSet<>();
	for(WorkspaceFolder workspaceFolder: workspaceFolders) 
		addProjectsForWorkspaceFolder(workspaceConfig, workspaceFolder, existingProjectNames);
	return workspaceConfig;
}
 
Example 13
protected void addProjectsForWorkspaceFolder(WorkspaceConfig workspaceConfig, WorkspaceFolder workspaceFolder, Set<String> existingNames) {
	if (workspaceFolder != null && workspaceFolder.getUri() != null) {
		FileProjectConfig project = new FileProjectConfig(uriExtensions.toUri(workspaceFolder.getUri()), getUniqueProjectName(workspaceFolder.getName(), existingNames));
		project.addSourceFolder(".");
		workspaceConfig.addProject(project);
	}
}
 
Example 14
Source Project: xtext-core   Source File: LanguageServerImpl.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
	if (initializeParams != null) {
		throw new IllegalStateException("This language server has already been initialized.");
	}
	URI baseDir = getBaseDir(params);
	if (languagesRegistry.getExtensionToFactoryMap().isEmpty()) {
		throw new IllegalStateException(
				"No Xtext languages have been registered. Please make sure you have added the languages\'s setup class in \'/META-INF/services/org.eclipse.xtext.ISetup\'");
	}
	initializeParams = params;

	InitializeResult result = new InitializeResult();

	result.setCapabilities(createServerCapabilities(params));
	access.addBuildListener(this);
	return requestManager.runWrite(() -> {
		if (workspaceManager.isSupportsWorkspaceFolders()) {
			List<WorkspaceFolder> workspaceFolders = params.getWorkspaceFolders();
			if (workspaceFolders == null)
				workspaceFolders = Collections.emptyList();
			workspaceManager.initialize(workspaceFolders, this::publishDiagnostics, CancelIndicator.NullImpl);
		} else {
			workspaceManager.initialize(baseDir, this::publishDiagnostics, CancelIndicator.NullImpl);
		}
		return result;
	}, (cancelIndicator, it) -> it).thenApply(it -> initializeResult = it);
}
 
Example 15
Source Project: xtext-core   Source File: WorkspaceManager.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Updates the workspace folders and refreshes the workspace.
 * 
 * @since 2.21
 */
public void didChangeWorkspaceFolders(DidChangeWorkspaceFoldersParams params, CancelIndicator cancelIndicator) {
	WorkspaceFoldersChangeEvent event = params.getEvent();
	Map<String, WorkspaceFolder> uri2workspaceFolder = new HashMap<>();
	workspaceFolders.forEach(it -> uri2workspaceFolder.put(it.getUri(), it));
	event.getRemoved().forEach(it -> uri2workspaceFolder.remove(it.getUri()));
	event.getAdded().forEach(it -> {
		if (!uri2workspaceFolder.containsKey(it.getUri())) 
			uri2workspaceFolder.put(it.getUri(), it);
	});
	this.workspaceFolders = new ArrayList<>(uri2workspaceFolder.values());
	refreshWorkspaceConfig(cancelIndicator);
}
 
Example 16
Source Project: lsp4intellij   Source File: DefaultLanguageClient.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<List<WorkspaceFolder>> workspaceFolders() {
    return LanguageClient.super.workspaceFolders();
}
 
Example 17
Source Project: MSPaintIDE   Source File: DefaultLanguageServerWrapper.java    License: MIT License 4 votes vote down vote up
private WorkspaceFolder getWorkspace(File file) {
    return getWorkspace(file.getAbsolutePath());
}
 
Example 18
Source Project: MSPaintIDE   Source File: DefaultLanguageServerWrapper.java    License: MIT License 4 votes vote down vote up
private WorkspaceFolder getWorkspace(String file) {
    var workspace = new WorkspaceFolder();
    workspace.setUri(getURI(file));
    workspace.setName(ProjectManager.getPPFProject().getName());
    return workspace;
}
 
Example 19
Source Project: MSPaintIDE   Source File: DefaultLanguageServerWrapper.java    License: MIT License 4 votes vote down vote up
private WorkspaceFolder getWorkspace(String file, String name) {
    var workspace = new WorkspaceFolder();
    workspace.setUri(getURI(file));
    workspace.setName(name);
    return workspace;
}
 
Example 20
public WorkspaceFolder getWorkspaceFolder()
{
    return workspaceFolder;
}
 
Example 21
Source Project: vscode-as3mxml   Source File: WorkspaceFolderData.java    License: Apache License 2.0 4 votes vote down vote up
public WorkspaceFolderData(WorkspaceFolder folder, IProjectConfigStrategy config)
{
	this.folder = folder;
	this.config = config;
}
 
Example 22
public SimpleProjectConfigStrategy(WorkspaceFolder workspaceFolder)
{
    this.workspaceFolder = workspaceFolder;
}
 
Example 23
public WorkspaceFolder getWorkspaceFolder()
{
    return workspaceFolder;
}
 
Example 24
Source Project: vscode-as3mxml   Source File: WorkspaceFolderManager.java    License: Apache License 2.0 4 votes vote down vote up
public List<WorkspaceFolder> getWorkspaceFolders()
{
    return workspaceFolders;
}
 
Example 25
Source Project: vscode-as3mxml   Source File: WorkspaceFolderManager.java    License: Apache License 2.0 4 votes vote down vote up
public WorkspaceFolderData getWorkspaceFolderData(WorkspaceFolder folder)
{
    return workspaceFolderToData.get(folder);
}
 
Example 26
Source Project: vscode-as3mxml   Source File: WorkspaceSymbolProvider.java    License: Apache License 2.0 4 votes vote down vote up
public List<? extends SymbolInformation> workspaceSymbol(WorkspaceSymbolParams params, CancelChecker cancelToken)
{
	cancelToken.checkCanceled();
	Set<String> qualifiedNames = new HashSet<>();
	List<SymbolInformation> result = new ArrayList<>();
	String query = params.getQuery();
	StringBuilder currentQuery = new StringBuilder();
	List<String> queries = new ArrayList<>();
	for(int i = 0, length = query.length(); i < length; i++)
	{
		String charAtI = query.substring(i, i + 1);
		if(i > 0 && charAtI.toUpperCase().equals(charAtI))
		{
			queries.add(currentQuery.toString().toLowerCase());
			currentQuery = new StringBuilder();
		}
		currentQuery.append(charAtI);
	}
	if(currentQuery.length() > 0)
	{
		queries.add(currentQuery.toString().toLowerCase());
	}
	for (WorkspaceFolder folder : workspaceFolderManager.getWorkspaceFolders())
	{
		WorkspaceFolderData folderData = workspaceFolderManager.getWorkspaceFolderData(folder);
		ILspProject project = folderData.project;
		if (project == null)
		{
			continue;
		}
		for (ICompilationUnit unit : project.getCompilationUnits())
		{
			if (unit == null)
			{
				continue;
			}
			UnitType unitType = unit.getCompilationUnitType();
			if (UnitType.SWC_UNIT.equals(unitType))
			{
				List<IDefinition> definitions = unit.getDefinitionPromises();
				for (IDefinition definition : definitions)
				{
					if (definition instanceof DefinitionPromise)
					{
						//we won't be able to detect what type of definition
						//this is without getting the actual definition from the
						//promise.
						DefinitionPromise promise = (DefinitionPromise) definition;
						definition = promise.getActualDefinition();
					}
					if (definition.isImplicit())
					{
						continue;
					}
					if (!matchesQueries(queries, definition.getQualifiedName()))
					{
						continue;
					}
					String qualifiedName = definition.getQualifiedName();
					if (qualifiedNames.contains(qualifiedName))
					{
						//we've already added this symbol
						//this can happen when there are multiple root
						//folders in the workspace
						continue;
					}
					SymbolInformation symbol = workspaceFolderManager.definitionToSymbolInformation(definition, project);
					if (symbol != null)
					{
						qualifiedNames.add(qualifiedName);
						result.add(symbol);
					}
				}
			}
			else if (UnitType.AS_UNIT.equals(unitType) || UnitType.MXML_UNIT.equals(unitType))
			{
				IASScope[] scopes;
				try
				{
					scopes = unit.getFileScopeRequest().get().getScopes();
				}
				catch (Exception e)
				{
					return Collections.emptyList();
				}
				for (IASScope scope : scopes)
				{
					querySymbolsInScope(queries, scope, qualifiedNames, project, result);
				}
			}
		}
	}
	cancelToken.checkCanceled();
	return result;
}
 
Example 27
Source Project: vscode-as3mxml   Source File: Main.java    License: Apache License 2.0 4 votes vote down vote up
public IProjectConfigStrategy create(WorkspaceFolder folder)
{
    return new ASConfigProjectConfigStrategy(folder);
}
 
Example 28
Source Project: vscode-as3mxml   Source File: ActionScriptServices.java    License: Apache License 2.0 4 votes vote down vote up
public List<WorkspaceFolder> getWorkspaceFolders()
{
    return workspaceFolderManager.getWorkspaceFolders();
}
 
Example 29
Source Project: vscode-as3mxml   Source File: ActionScriptServices.java    License: Apache License 2.0 4 votes vote down vote up
public WorkspaceFolderData getWorkspaceFolderData(WorkspaceFolder folder)
{
    return workspaceFolderManager.getWorkspaceFolderData(folder);
}
 
Example 30
Source Project: vscode-as3mxml   Source File: ActionScriptServices.java    License: Apache License 2.0 4 votes vote down vote up
public void removeWorkspaceFolder(WorkspaceFolder folder)
{
    workspaceFolderManager.removeWorkspaceFolder(folder);
}