下面列出了怎么用org.eclipse.lsp4j.DidSaveTextDocumentParams的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Notifies the server that the corresponding document has been saved
*/
public void documentSaved() {
pool(() -> {
if (!editor.isDisposed()) {
DidSaveTextDocumentParams params = new DidSaveTextDocumentParams(identifier, editor.getDocument().getText());
requestManager.didSave(params);
}
});
}
public void documentSaved(long timestamp) {
this.modificationStamp = timestamp;
ServerCapabilities serverCapabilities = languageServerWrapper.getServerCapabilities();
if(serverCapabilities != null ) {
Either<TextDocumentSyncKind, TextDocumentSyncOptions> textDocumentSync = serverCapabilities.getTextDocumentSync();
if(textDocumentSync.isRight() && textDocumentSync.getRight().getSave() == null) {
return;
}
}
TextDocumentIdentifier identifier = new TextDocumentIdentifier(fileUri.toString());
DidSaveTextDocumentParams params = new DidSaveTextDocumentParams(identifier, document.getText());
languageServerWrapper.getInitializedServer().thenAcceptAsync(ls -> ls.getTextDocumentService().didSave(params));
}
@Override
public void didSave(DidSaveTextDocumentParams params) {
computeAsync((monitor) -> {
// A document was saved, collect documents to revalidate
SaveContext context = new SaveContext(params.getTextDocument().getUri());
doSave(context);
return null;
});
}
private String retrieveFullText(DidSaveTextDocumentParams params) {
String camelText = params.getText();
if (camelText == null) {
camelText = camelLanguageServer.getTextDocumentService().getOpenedDocument(params.getTextDocument().getUri()).getText();
}
return camelText;
}
private TextDocumentIdentifier initAnLaunchDiagnostic() throws FileNotFoundException {
File f = new File("src/test/resources/workspace/diagnostic/camel-with-unknownParameter.xml");
camelLanguageServer = initializeLanguageServer(new FileInputStream(f), ".xml");
TextDocumentIdentifier textDocumentIdentifier = new TextDocumentIdentifier(DUMMY_URI+".xml");
DidSaveTextDocumentParams params = new DidSaveTextDocumentParams(textDocumentIdentifier);
camelLanguageServer.getTextDocumentService().didSave(params);
await().timeout(AWAIT_TIMEOUT).untilAsserted(() -> assertThat(lastPublishedDiagnostics).isNotNull());
await().timeout(AWAIT_TIMEOUT).untilAsserted(() -> assertThat(lastPublishedDiagnostics.getDiagnostics()).hasSize(1));
return textDocumentIdentifier;
}
private TextDocumentIdentifier initAnLaunchDiagnostic() throws FileNotFoundException {
File f = new File("src/test/resources/workspace/diagnostic/camel-with-invalid-enum.xml");
camelLanguageServer = initializeLanguageServer(new FileInputStream(f), ".xml");
TextDocumentIdentifier textDocumentIdentifier = new TextDocumentIdentifier(DUMMY_URI+".xml");
DidSaveTextDocumentParams params = new DidSaveTextDocumentParams(textDocumentIdentifier);
camelLanguageServer.getTextDocumentService().didSave(params);
await().timeout(AWAIT_TIMEOUT).untilAsserted(() -> assertThat(lastPublishedDiagnostics).isNotNull());
await().timeout(AWAIT_TIMEOUT).untilAsserted(() -> assertThat(lastPublishedDiagnostics.getDiagnostics()).hasSize(1));
return textDocumentIdentifier;
}
protected void testDiagnostic(String fileUnderTest, int expectedNumberOfError, String extension) throws FileNotFoundException {
File f = new File("src/test/resources/workspace/diagnostic/" + fileUnderTest + extension);
camelLanguageServer = initializeLanguageServer(new FileInputStream(f), extension);
DidSaveTextDocumentParams params = new DidSaveTextDocumentParams(new TextDocumentIdentifier(DUMMY_URI+extension));
camelLanguageServer.getTextDocumentService().didSave(params);
await().timeout(AWAIT_TIMEOUT).untilAsserted(() -> assertThat(lastPublishedDiagnostics).isNotNull());
await().timeout(AWAIT_TIMEOUT).untilAsserted(() -> assertThat(lastPublishedDiagnostics.getDiagnostics()).hasSize(expectedNumberOfError));
}
/** Save the given, open file's in-memory content to disk. Does *not* close the file. */
protected void saveOpenedFile(FileURI fileURI) {
if (!isOpen(fileURI)) {
Assert.fail("file is not open: " + fileURI);
}
OpenFileInfo info = openFiles.get(fileURI);
// 1) save current content to disk
changeFileOnDiskWithoutNotification(fileURI, info.content);
// 2) notify LSP server
VersionedTextDocumentIdentifier docId = new VersionedTextDocumentIdentifier(fileURI.toString(), info.version);
DidSaveTextDocumentParams params = new DidSaveTextDocumentParams(docId);
languageServer.didSave(params);
}
public void didSave(DidSaveTextDocumentParams params) {
ISchedulingRule rule = JDTUtils.getRule(params.getTextDocument().getUri());
try {
JobHelpers.waitForJobs(DocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS, new NullProgressMonitor());
ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
handleSaved(params);
}
}, rule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
} catch (CoreException e) {
JavaLanguageServerPlugin.logException("Handle document save ", e);
}
}
private void saveDocument(ICompilationUnit cu) throws Exception {
DidSaveTextDocumentParams saveParms = new DidSaveTextDocumentParams();
TextDocumentIdentifier textDocument = new TextDocumentIdentifier();
textDocument.setUri(JDTUtils.toURI(cu));
saveParms.setTextDocument(textDocument);
saveParms.setText(cu.getSource());
lifeCycleHandler.didSave(saveParms);
waitForBackgroundJobs();
}
@Override
public void didSave(DidSaveTextDocumentParams params) {
// nothing to handle on save at this time
}
@Override
public void didSave(DidSaveTextDocumentParams params) {
LOGGER.info("didSave: {}", params.getTextDocument());
new DiagnosticRunner(getCamelCatalog(), camelLanguageServer).compute(params);
}
public void compute(DidSaveTextDocumentParams params) {
String camelText = retrieveFullText(params);
computeDiagnostics(camelText, params.getTextDocument().getUri());
}
@Override
public void didSave(DidSaveTextDocumentParams params) {
// refresh all tripleset
refreshFileTripleSet();
}
@Override
public void didSave(DidSaveTextDocumentParams params) {
lspBuilder.didSave(params);
}
public void didSave(DidSaveTextDocumentParams params) {
runBuildable("didSave", () -> toBuildable(params));
}
/**
* Evaluate the params and deduce the respective build command.
*/
protected XBuildable toBuildable(DidSaveTextDocumentParams params) {
return workspaceManager.didSave(getURI(params.getTextDocument()));
}
@Override
public void didSave(DidSaveTextDocumentParams arg0) {
//TODO: nothing for now?
}
@Override
public void didSave(DidSaveTextDocumentParams params) {
LOGGER.debug("didSave: {}", params.getTextDocument());
}
@Override
public void didSave(DidSaveTextDocumentParams params) {
logInfo(">> document/didSave");
documentLifeCycleHandler.didSave(params);
}
@Override
public void didSave(DidSaveTextDocumentParams params) {
logInfo(">> document/didSave");
documentLifeCycleHandler.didSave(params);
}
/**
* Called when a file being edited is saved.
*/
@Override
public void didSave(DidSaveTextDocumentParams params)
{
if(realTimeProblems)
{
//as long as we're checking on change, we shouldn't need to do
//anything on save because we should already have the correct state
return;
}
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;
}
WorkspaceFolderData folderData = workspaceFolderManager.getWorkspaceFolderDataForSourceFile(path);
if (folderData == null)
{
return;
}
getProject(folderData);
ILspProject project = folderData.project;
if (project == null)
{
//something went wrong while creating the project
return;
}
//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);
}
checkProjectForProblems(folderData);
}
@Override
public void didSave(DidSaveTextDocumentParams params) {
// nothing to do
}
@Override
public void didSave(DidSaveTextDocumentParams params) {
}
@Override
public void didSave(DidSaveTextDocumentParams params) {
System.out.println("didSave");
}
/**
* The document save notification is sent from the client to the server when
* the document for saved in the client.
*
* Registration Options: TextDocumentSaveRegistrationOptions
*/
@JsonNotification
void didSave(DidSaveTextDocumentParams params);