org.eclipse.lsp4j.DidCloseTextDocumentParams Java Examples

The following examples show how to use org.eclipse.lsp4j.DidCloseTextDocumentParams. 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: SyntaxServerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDidClose() throws Exception {
	URI fileURI = openFile("maven/salut4", "src/main/java/java/TestSyntaxError.java");
	Job.getJobManager().join(SyntaxDocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS, monitor);

	String fileUri = ResourceUtils.fixURI(fileURI);
	TextDocumentIdentifier identifier = new TextDocumentIdentifier(fileUri);
	server.didClose(new DidCloseTextDocumentParams(identifier));
	Job.getJobManager().join(SyntaxDocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS, monitor);

	List<PublishDiagnosticsParams> diagnosticReports = getClientRequests("publishDiagnostics");
	assertEquals(2, diagnosticReports.size());
	PublishDiagnosticsParams params = diagnosticReports.get(1);
	assertEquals(fileUri, params.getUri());
	assertNotNull(params.getDiagnostics());
	assertTrue(params.getDiagnostics().isEmpty());
}
 
Example #2
Source File: TeiidDdlTextDocumentService.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Override
public void didClose(DidCloseTextDocumentParams params) {
    LOGGER.debug("didClose: {}", params.getTextDocument());
    String uri = params.getTextDocument().getUri();

    /*
     * The rule observed by VS Code servers as explained in LSP specification is to
     * clear the Diagnostic when it is related to a single file.
     * https://microsoft.github.io/language-server-protocol/specification#
     * textDocument_publishDiagnostics
     *
     * clear diagnostics before removing document.
     */

    new DdlDiagnostics(this.teiidLanguageServer).clearDiagnostics(uri);

    openedDocuments.remove(uri);
}
 
Example #3
Source File: AbstractIdeTest.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private void closeFile(FileURI fileURI, boolean discardChanges) {
	if (!isOpen(fileURI)) {
		Assert.fail("trying to close a file that is not open: " + fileURI);
	}
	boolean dirty = isDirty(fileURI);
	if (dirty && !discardChanges) {
		Assert.fail("trying to close a file with unsaved changes: " + fileURI);
	} else if (!dirty && discardChanges) {
		Assert.fail("no unsaved changes to discard in file: " + fileURI);
	}

	OpenFileInfo info = openFiles.remove(fileURI);
	if (dirty) {
		// when closing a file with unsaved changes, LSP clients send a 'textDocument/didChange' to bring its
		// content back to the content on disk
		String contentOnDisk = getContentOfFileOnDisk(fileURI);
		DidChangeTextDocumentParams params = new DidChangeTextDocumentParams(
				new VersionedTextDocumentIdentifier(fileURI.toString(), info.version + 1),
				Collections.singletonList(new TextDocumentContentChangeEvent(contentOnDisk)));
		languageServer.didChange(params);
	}
	languageServer.didClose(new DidCloseTextDocumentParams(new TextDocumentIdentifier(fileURI.toString())));
	joinServerRequests();
}
 
Example #4
Source File: RdfLintLanguageServerTest.java    From rdflint with MIT License 6 votes vote down vote up
@Test
public void diagnosticsClose() throws Exception {
  RdfLintLanguageServer lsp = new RdfLintLanguageServer();
  InitializeParams initParams = new InitializeParams();
  String rootPath = this.getClass().getClassLoader().getResource("testValidatorsImpl/").getPath();
  String parentPath = rootPath + "TrimValidator/turtle_needtrim";
  initParams.setRootUri(RdfLintLanguageServer.convertFilePath2Uri(parentPath));
  lsp.initialize(initParams);

  LanguageClient client = mock(LanguageClient.class);
  lsp.connect(client);

  DidCloseTextDocumentParams closeParams = new DidCloseTextDocumentParams();
  closeParams.setTextDocument(new TextDocumentIdentifier());
  closeParams.getTextDocument()
      .setUri(RdfLintLanguageServer.convertFilePath2Uri(parentPath + "/needtrim.rdf"));

  lsp.didClose(closeParams);
  verify(client, times(2)).publishDiagnostics(any());
}
 
Example #5
Source File: WorkspaceEventsHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public void didChangeWatchedFiles(DidChangeWatchedFilesParams param) {
	List<FileEvent> changes = param.getChanges().stream().distinct().collect(Collectors.toList());
	for (FileEvent fileEvent : changes) {
		CHANGE_TYPE changeType = toChangeType(fileEvent.getType());
		if (changeType == CHANGE_TYPE.DELETED) {
			cleanUpDiagnostics(fileEvent.getUri());
			handler.didClose(new DidCloseTextDocumentParams(new TextDocumentIdentifier(fileEvent.getUri())));
			discardWorkingCopies(fileEvent.getUri());
		}
		ICompilationUnit unit = JDTUtils.resolveCompilationUnit(fileEvent.getUri());
		if (unit != null && changeType == CHANGE_TYPE.CREATED && !unit.exists()) {
			final ICompilationUnit[] units = new ICompilationUnit[1];
			units[0] = unit;
			try {
				ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
					@Override
					public void run(IProgressMonitor monitor) throws CoreException {
						units[0] = createCompilationUnit(units[0]);
					}
				}, new NullProgressMonitor());
			} catch (CoreException e) {
				JavaLanguageServerPlugin.logException(e.getMessage(), e);
			}
			unit = units[0];
		}
		if (unit != null) {
			if (unit.isWorkingCopy()) {
				continue;
			}
			if (changeType == CHANGE_TYPE.DELETED || changeType == CHANGE_TYPE.CHANGED) {
				if (unit.equals(CoreASTProvider.getInstance().getActiveJavaElement())) {
					CoreASTProvider.getInstance().disposeAST();
				}
			}
		}
		pm.fileChanged(fileEvent.getUri(), changeType);
	}
}
 
Example #6
Source File: EditorEventManager.java    From lsp4intellij with Apache License 2.0 5 votes vote down vote up
/**
 * Notifies the server that the corresponding document has been closed
 */
public void documentClosed() {
    pool(() -> {
        if (this.isOpen) {
            requestManager.didClose(new DidCloseTextDocumentParams(identifier));
            isOpen = false;
            EditorEventManagerBase.editorToManager.remove(editor);
            EditorEventManagerBase.uriToManager.remove(FileUtils.editorToURIString(editor));
        } else {
            LOG.warn("Editor " + identifier.getUri() + " was already closed");
        }
    });
}
 
Example #7
Source File: AbstractLanguageServerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void close(final String fileUri) {
  DidCloseTextDocumentParams _didCloseTextDocumentParams = new DidCloseTextDocumentParams();
  final Procedure1<DidCloseTextDocumentParams> _function = (DidCloseTextDocumentParams it) -> {
    TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(fileUri);
    it.setTextDocument(_textDocumentIdentifier);
  };
  DidCloseTextDocumentParams _doubleArrow = ObjectExtensions.<DidCloseTextDocumentParams>operator_doubleArrow(_didCloseTextDocumentParams, _function);
  this.languageServer.didClose(_doubleArrow);
}
 
Example #8
Source File: BaseDocumentLifeCycleHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public void didClose(DidCloseTextDocumentParams params) {
	ISchedulingRule rule = JDTUtils.getRule(params.getTextDocument().getUri());
	try {
		ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
			@Override
			public void run(IProgressMonitor monitor) throws CoreException {
				handleClosed(params);
			}
		}, rule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
	} catch (CoreException e) {
		JavaLanguageServerPlugin.logException("Handle document close ", e);
	}
}
 
Example #9
Source File: BaseDocumentLifeCycleHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public ICompilationUnit handleClosed(DidCloseTextDocumentParams params) {
	String uri = params.getTextDocument().getUri();
	ICompilationUnit unit = JDTUtils.resolveCompilationUnit(uri);
	if (unit == null) {
		return unit;
	}
	try {
		synchronized (toReconcile) {
			toReconcile.remove(unit);
		}
		if (isSyntaxMode(unit) || unit.getResource().isDerived()) {
			createDiagnosticsHandler(unit).clearDiagnostics();
		} else if (hasUnsavedChanges(unit)) {
			unit.discardWorkingCopy();
			unit.becomeWorkingCopy(new NullProgressMonitor());
			publishDiagnostics(unit, new NullProgressMonitor());
		}
		if (unit.equals(sharedASTProvider.getActiveJavaElement())) {
			sharedASTProvider.disposeAST();
		}
		unit.discardWorkingCopy();
		if (JDTUtils.isDefaultProject(unit)) {
			File f = new File(unit.getUnderlyingResource().getLocationURI());
			if (!f.exists()) {
				unit.delete(true, null);
			}
		}
	} catch (CoreException e) {
		JavaLanguageServerPlugin.logException("Error while handling document close. URI: " + uri, e);
	}

	return unit;
}
 
Example #10
Source File: RdfLintLanguageServer.java    From rdflint with MIT License 5 votes vote down vote up
@Override
public void didClose(DidCloseTextDocumentParams params) {
  // remove source from map
  sourceTextMap.remove(params.getTextDocument().getUri());

  // clear diagnostics
  PublishDiagnosticsParams diagnostics = new PublishDiagnosticsParams();
  diagnostics.setUri(params.getTextDocument().getUri());
  diagnostics.setDiagnostics(new LinkedList<>());
  this.client.publishDiagnostics(diagnostics);

  // diagnostics
  diagnostics(params.getTextDocument().getUri());
}
 
Example #11
Source File: CamelDiagnosticTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Test
void testValidationErrorClearedOnClose() throws Exception {
	testDiagnostic("camel-with-endpoint-error", 1, ".xml");
	
	DidCloseTextDocumentParams params = new DidCloseTextDocumentParams(new TextDocumentIdentifier(DUMMY_URI+".xml"));
	camelLanguageServer.getTextDocumentService().didClose(params);
	
	await().timeout(AWAIT_TIMEOUT).untilAsserted(() -> assertThat(lastPublishedDiagnostics.getDiagnostics()).isEmpty());
}
 
Example #12
Source File: CamelTextDocumentService.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
@Override
public void didClose(DidCloseTextDocumentParams params) {
	LOGGER.info("didClose: {}", params.getTextDocument());
	String uri = params.getTextDocument().getUri();
	openedDocuments.remove(uri);
	/* The rule observed by VS Code servers as explained in LSP specification is to clear the Diagnostic when it is related to a single file.
	 * https://microsoft.github.io/language-server-protocol/specification#textDocument_publishDiagnostics
	 * */
	new DiagnosticRunner(getCamelCatalog(), camelLanguageServer).clear(uri);
}
 
Example #13
Source File: XMLTextDocumentService.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void didClose(DidCloseTextDocumentParams params) {
	documents.onDidCloseTextDocument(params);
	TextDocumentIdentifier document = params.getTextDocument();
	String uri = document.getUri();
	xmlLanguageServer.getLanguageClient()
			.publishDiagnostics(new PublishDiagnosticsParams(uri, Collections.emptyList()));
	getLimitExceededWarner().evictValue(uri);
}
 
Example #14
Source File: TextDocuments.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
public T onDidCloseTextDocument(DidCloseTextDocumentParams params) {
	synchronized (documents) {
		T document = getDocument(params.getTextDocument());
		if (document != null) {
			documents.remove(params.getTextDocument().getUri());
		}
		return document;
	}
}
 
Example #15
Source File: DocumentContentSynchronizer.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
public void documentClosed() {
    // When LS is shut down all documents are being disconnected. No need to send "didClose" message to the LS that is being shut down or not yet started
    if (languageServerWrapper.isActive()) {
        TextDocumentIdentifier identifier = new TextDocumentIdentifier(fileUri.toString());
        DidCloseTextDocumentParams params = new DidCloseTextDocumentParams(identifier);
        languageServerWrapper.getInitializedServer().thenAcceptAsync(ls -> ls.getTextDocumentService().didClose(params));
    }
}
 
Example #16
Source File: DocumentLifeCycleHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void closeDocument(ICompilationUnit cu) {
	DidCloseTextDocumentParams closeParms = new DidCloseTextDocumentParams();
	TextDocumentIdentifier textDocument = new TextDocumentIdentifier();
	textDocument.setUri(JDTUtils.toURI(cu));
	closeParms.setTextDocument(textDocument);
	lifeCycleHandler.didClose(closeParms);
}
 
Example #17
Source File: LanguageServerImpl.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Evaluate the params and deduce the respective build command.
 */
protected Buildable toBuildable(DidCloseTextDocumentParams params) {
	return workspaceManager.didClose(getURI(params.getTextDocument()));
}
 
Example #18
Source File: ActionScriptServices.java    From vscode-as3mxml with Apache License 2.0 4 votes vote down vote up
/**
 * Called when a file is closed in Visual Studio Code. We should no longer
 * store the file as a String, and we can load the contents from the file
 * system.
 */
@Override
public void didClose(DidCloseTextDocumentParams params)
{
    TextDocumentIdentifier textDocument = params.getTextDocument();
    String textDocumentUri = textDocument.getUri();
    if (!textDocumentUri.endsWith(FILE_EXTENSION_AS)
            && !textDocumentUri.endsWith(FILE_EXTENSION_MXML))
    {
        //code intelligence is available only in .as and .mxml files
        //so we ignore other file extensions
        return;
    }
    Path path = LanguageServerCompilerUtils.getPathFromLanguageServerURI(textDocumentUri);
    if (path == null)
    {
        return;
    }

    fileTracker.closeFile(path);

    boolean clearProblems = false;

    WorkspaceFolderData folderData = workspaceFolderManager.getWorkspaceFolderDataForSourceFile(path);
    if (folderData == null)
    {
        //if we can't figure out which workspace the file is in, then clear
        //the problems completely because we want to display problems only
        //while it is open
        clearProblems = true;
    }
    else
    {
        if (fallbackConfig != null && folderData.equals(workspaceFolderManager.getFallbackFolderData()))
        {
            fallbackConfig.didClose(path);
            clearProblems = true;
        }

        getProject(folderData);
        ILspProject project = folderData.project;
        URI uri = path.toUri();
        if(project == null)
        {
            //if the current project isn't properly configured, we want to
            //display problems only while a file is open
            clearProblems = true;
        }
        else if(notOnSourcePathSet.contains(uri))
        {
            //if the file is outside of the project's source path, we want
            //to display problems only while it is open
            clearProblems = true;
            notOnSourcePathSet.remove(uri);
        }

        //if it's an included file, switch to the parent file
        IncludeFileData includeFileData = folderData.includedFiles.get(path.toString());
        if (includeFileData != null)
        {
            path = Paths.get(includeFileData.parentPath);
        }
    }

    if (clearProblems)
    {
        //immediately clear any diagnostics published for this file
        clearProblemsForURI(path.toUri());
        return;
    }

    //the contents of the file may have been modified, and then reverted
    //without saving changes, so re-check for errors with the file system
    //version of the file
    checkProjectForProblems(folderData);
}
 
Example #19
Source File: LanguageServerImpl.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void didClose(DidCloseTextDocumentParams params) {
	runBuildable(() -> toBuildable(params));
}
 
Example #20
Source File: JDTLanguageServer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void didClose(DidCloseTextDocumentParams params) {
	logInfo(">> document/didClose");
	documentLifeCycleHandler.didClose(params);
}
 
Example #21
Source File: MockLanguageServer.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void didClose(DidCloseTextDocumentParams params) {
}
 
Example #22
Source File: DocumentServiceStub.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void didClose(DidCloseTextDocumentParams params) {
  System.out.println("didClose");
}
 
Example #23
Source File: SyntaxLanguageServer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void didClose(DidCloseTextDocumentParams params) {
	logInfo(">> document/didClose");
	documentLifeCycleHandler.didClose(params);
}
 
Example #24
Source File: DocumentLifeCycleHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public ICompilationUnit handleClosed(DidCloseTextDocumentParams params) {
	ICompilationUnit unit = super.handleClosed(params);
	uninstallSemanticHighlightings(params.getTextDocument().getUri());
	return unit;
}
 
Example #25
Source File: BasicDocument.java    From MSPaintIDE with MIT License 4 votes vote down vote up
@Override
public void close() {
    this.opened = false;

    this.requestManager.didClose(new DidCloseTextDocumentParams(new TextDocumentIdentifier(getURI())));
}
 
Example #26
Source File: TextDocumentServiceImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void didClose(DidCloseTextDocumentParams params) {
    openedDocuments.remove(params.getTextDocument().getUri());
}
 
Example #27
Source File: XLanguageServerImpl.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void didClose(DidCloseTextDocumentParams params) {
	openFilesManager.closeFile(getURI(params.getTextDocument()));
}
 
Example #28
Source File: FileContentsTracker.java    From groovy-language-server with Apache License 2.0 4 votes vote down vote up
public void didClose(DidCloseTextDocumentParams params) {
	URI uri = URI.create(params.getTextDocument().getUri());
	openFiles.remove(uri);
	changedFiles.add(uri);
}
 
Example #29
Source File: GroovyServices.java    From groovy-language-server with Apache License 2.0 4 votes vote down vote up
@Override
public void didClose(DidCloseTextDocumentParams params) {
	fileContentsTracker.didClose(params);
	URI uri = URI.create(params.getTextDocument().getUri());
	compileAndVisitAST(uri);
}
 
Example #30
Source File: TextDocumentService.java    From lsp4j with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * The document close notification is sent from the client to the server
 * when the document got closed in the client. The document's truth now
 * exists where the document's uri points to (e.g. if the document's uri is
 * a file uri the truth now exists on disk).
 * 
 * Registration Options: TextDocumentRegistrationOptions
 */
@JsonNotification
void didClose(DidCloseTextDocumentParams params);