org.eclipse.lsp4j.WorkspaceFolder Java Examples

The following examples show how to use org.eclipse.lsp4j.WorkspaceFolder. 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 File: ActionScriptServices.java    From vscode-as3mxml with 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 #2
Source File: ActionScriptServices.java    From vscode-as3mxml with 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 File: WorkspaceFolderManager.java    From vscode-as3mxml with 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 #4
Source File: LSPIJUtils.java    From intellij-quarkus with 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
Source File: WorkspaceManager.java    From xtext-core with 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 #6
Source File: LanguageServerImpl.java    From xtext-core with 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 #7
Source File: MultiRootWorkspaceConfigFactory.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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 #8
Source File: MultiRootWorkspaceConfigFactory.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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 #9
Source File: IndexOnlyProjectTest.java    From xtext-core with 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 #10
Source File: SourceFolderCustomImplTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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 File: WorkspaceFolderManager.java    From vscode-as3mxml with 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 #12
Source File: WorkspaceFolderManager.java    From vscode-as3mxml with 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 #13
Source File: ASConfigProjectConfigStrategy.java    From vscode-as3mxml with Apache License 2.0 5 votes vote down vote up
public ASConfigProjectConfigStrategy(WorkspaceFolder workspaceFolder)
{
    this.workspaceFolder = workspaceFolder;

    Path workspacePath = Paths.get(URI.create(workspaceFolder.getUri()));
    asconfigPath = workspacePath.resolve(ASCONFIG_JSON);
}
 
Example #14
Source File: DefaultLanguageServerWrapper.java    From MSPaintIDE with 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 #15
Source File: LanguageClientImpl.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
@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 #16
Source File: WorkspaceFoldersChangeEvent.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
public WorkspaceFoldersChangeEvent(@NonNull final List<WorkspaceFolder> added, @NonNull final List<WorkspaceFolder> removed) {
  this.added = Preconditions.<List<WorkspaceFolder>>checkNotNull(added, "added");
  this.removed = Preconditions.<List<WorkspaceFolder>>checkNotNull(removed, "removed");
}
 
Example #17
Source File: AbstractLanguageServerTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected InitializeResult initialize(final Procedure1<? super InitializeParams> initializer, final boolean callInitialized) {
  try {
    InitializeParams _initializeParams = new InitializeParams();
    final Procedure1<InitializeParams> _function = (InitializeParams it) -> {
      it.setProcessId(Integer.valueOf(1));
      it.setRootUri(this._uriExtensions.toUriString(this.root.toURI().normalize()));
      String _rootUri = it.getRootUri();
      WorkspaceFolder _workspaceFolder = new WorkspaceFolder(_rootUri, "");
      it.setWorkspaceFolders(Collections.<WorkspaceFolder>unmodifiableList(CollectionLiterals.<WorkspaceFolder>newArrayList(_workspaceFolder)));
    };
    final InitializeParams params = ObjectExtensions.<InitializeParams>operator_doubleArrow(_initializeParams, _function);
    if (initializer!=null) {
      initializer.apply(params);
    }
    Boolean _elvis = null;
    ClientCapabilities _capabilities = params.getCapabilities();
    TextDocumentClientCapabilities _textDocument = null;
    if (_capabilities!=null) {
      _textDocument=_capabilities.getTextDocument();
    }
    DocumentSymbolCapabilities _documentSymbol = null;
    if (_textDocument!=null) {
      _documentSymbol=_textDocument.getDocumentSymbol();
    }
    Boolean _hierarchicalDocumentSymbolSupport = null;
    if (_documentSymbol!=null) {
      _hierarchicalDocumentSymbolSupport=_documentSymbol.getHierarchicalDocumentSymbolSupport();
    }
    if (_hierarchicalDocumentSymbolSupport != null) {
      _elvis = _hierarchicalDocumentSymbolSupport;
    } else {
      _elvis = Boolean.valueOf(false);
    }
    this.hierarchicalDocumentSymbolSupport = (_elvis).booleanValue();
    final InitializeResult result = this.languageServer.initialize(params).get();
    if (callInitialized) {
      this.languageServer.initialized(null);
    }
    return result;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #18
Source File: SimpleProjectConfigStrategy.java    From vscode-as3mxml with Apache License 2.0 4 votes vote down vote up
public SimpleProjectConfigStrategy(WorkspaceFolder workspaceFolder)
{
    this.workspaceFolder = workspaceFolder;
}
 
Example #19
Source File: DefaultLanguageServerWrapper.java    From MSPaintIDE with MIT License 4 votes vote down vote up
private WorkspaceFolder getWorkspace(File file) {
    return getWorkspace(file.getAbsolutePath());
}
 
Example #20
Source File: WorkspaceManager.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected List<WorkspaceFolder> getWorkspaceFolders() {
	return workspaceFolders;
}
 
Example #21
Source File: DefaultLanguageClient.java    From lsp4intellij with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<List<WorkspaceFolder>> workspaceFolders() {
    return LanguageClient.super.workspaceFolders();
}
 
Example #22
Source File: MultiProjectWorkspaceConfigFactory.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void addProjectsForWorkspaceFolder(WorkspaceConfig workspaceConfig, WorkspaceFolder workspaceFolder, Set<String> existingNames) {
	if (workspaceFolder != null && workspaceFolder.getUri() != null)
		findProjects(workspaceConfig, uriExtensions.toUri(workspaceFolder.getUri()));
}
 
Example #23
Source File: WorkspaceFoldersChangeEvent.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * The array of added workspace folders
 */
@Pure
@NonNull
public List<WorkspaceFolder> getAdded() {
  return this.added;
}
 
Example #24
Source File: WorkspaceFoldersChangeEvent.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * The array of added workspace folders
 */
public void setAdded(@NonNull final List<WorkspaceFolder> added) {
  this.added = Preconditions.checkNotNull(added, "added");
}
 
Example #25
Source File: WorkspaceFoldersChangeEvent.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * The array of the removed workspace folders
 */
@Pure
@NonNull
public List<WorkspaceFolder> getRemoved() {
  return this.removed;
}
 
Example #26
Source File: WorkspaceFoldersChangeEvent.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * The array of the removed workspace folders
 */
public void setRemoved(@NonNull final List<WorkspaceFolder> removed) {
  this.removed = Preconditions.checkNotNull(removed, "removed");
}
 
Example #27
Source File: InitializeParamsTypeAdapter.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
protected List<WorkspaceFolder> readWorkspaceFolders(final JsonReader in) throws IOException {
  return gson.fromJson(in, WORKSPACEFOLDERS_TYPE_TOKEN.getType());
}
 
Example #28
Source File: InitializeParamsTypeAdapter.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
protected void writeWorkspaceFolders(final JsonWriter out, final List<WorkspaceFolder> value) throws IOException {
  gson.toJson(value, WORKSPACEFOLDERS_TYPE_TOKEN.getType(), out);
}
 
Example #29
Source File: MockLanguageClient.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<List<WorkspaceFolder>> workspaceFolders() {
	throw new UnsupportedOperationException();
}
 
Example #30
Source File: DefaultLanguageServerWrapper.java    From MSPaintIDE with 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;
}