-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1425 support all text document synchronization types, upgrade to nex…
…t ls-api version
- Loading branch information
Evgen Vidolob
committed
Aug 30, 2016
1 parent
0530607
commit be5d5d0
Showing
32 changed files
with
503 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
.../eclipse/che/plugin/languageserver/ide/editor/LanguageServerReconcileStrategyFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2016 Codenvy, S.A. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.che.plugin.languageserver.ide.editor; | ||
|
||
import io.typefox.lsapi.ServerCapabilities; | ||
|
||
/** | ||
* @author Evgen Vidolob | ||
*/ | ||
public interface LanguageServerReconcileStrategyFactory { | ||
LanguageServerReconcileStrategy build(ServerCapabilities serverCapabilities); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...va/org/eclipse/che/plugin/languageserver/ide/editor/sync/FullTextDocumentSynchronize.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2016 Codenvy, S.A. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.che.plugin.languageserver.ide.editor.sync; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.Singleton; | ||
|
||
import org.eclipse.che.ide.api.editor.document.Document; | ||
import org.eclipse.che.ide.api.editor.events.DocumentChangeEvent; | ||
import org.eclipse.che.ide.dto.DtoFactory; | ||
import org.eclipse.che.plugin.languageserver.ide.service.TextDocumentServiceClient; | ||
import org.eclipse.che.plugin.languageserver.shared.lsapi.DidChangeTextDocumentParamsDTO; | ||
import org.eclipse.che.plugin.languageserver.shared.lsapi.TextDocumentContentChangeEventDTO; | ||
import org.eclipse.che.plugin.languageserver.shared.lsapi.VersionedTextDocumentIdentifierDTO; | ||
|
||
import java.util.Collections; | ||
|
||
/** | ||
* Handles full text synchronization | ||
* | ||
* @author Evgen Vidolob | ||
*/ | ||
@Singleton | ||
class FullTextDocumentSynchronize implements TextDocumentSynchronize { | ||
|
||
private final DtoFactory dtoFactory; | ||
private final TextDocumentServiceClient textDocumentService; | ||
|
||
@Inject | ||
public FullTextDocumentSynchronize(DtoFactory dtoFactory, TextDocumentServiceClient textDocumentService) { | ||
this.dtoFactory = dtoFactory; | ||
this.textDocumentService = textDocumentService; | ||
} | ||
|
||
@Override | ||
public void syncTextDocument(DocumentChangeEvent event, int version) { | ||
Document document = event.getDocument().getDocument(); | ||
|
||
DidChangeTextDocumentParamsDTO changeDTO = dtoFactory.createDto(DidChangeTextDocumentParamsDTO.class); | ||
String uri = document.getFile().getLocation().toString(); | ||
changeDTO.setUri(uri); | ||
VersionedTextDocumentIdentifierDTO versionedDocId = dtoFactory.createDto(VersionedTextDocumentIdentifierDTO.class); | ||
versionedDocId.setUri(uri); | ||
versionedDocId.setVersion(version); | ||
changeDTO.setTextDocument(versionedDocId); | ||
TextDocumentContentChangeEventDTO actualChange = dtoFactory.createDto(TextDocumentContentChangeEventDTO.class); | ||
|
||
actualChange.setText(event.getDocument().getDocument().getContents()); | ||
changeDTO.setContentChanges(Collections.singletonList(actualChange)); | ||
textDocumentService.didChange(changeDTO); | ||
} | ||
|
||
} |
82 changes: 82 additions & 0 deletions
82
...eclipse/che/plugin/languageserver/ide/editor/sync/IncrementalTextDocumentSynchronize.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2016 Codenvy, S.A. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.che.plugin.languageserver.ide.editor.sync; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.Singleton; | ||
|
||
import org.eclipse.che.ide.api.editor.document.Document; | ||
import org.eclipse.che.ide.api.editor.events.DocumentChangeEvent; | ||
import org.eclipse.che.ide.api.editor.text.TextPosition; | ||
import org.eclipse.che.ide.dto.DtoFactory; | ||
import org.eclipse.che.plugin.languageserver.ide.service.TextDocumentServiceClient; | ||
import org.eclipse.che.plugin.languageserver.shared.lsapi.DidChangeTextDocumentParamsDTO; | ||
import org.eclipse.che.plugin.languageserver.shared.lsapi.PositionDTO; | ||
import org.eclipse.che.plugin.languageserver.shared.lsapi.RangeDTO; | ||
import org.eclipse.che.plugin.languageserver.shared.lsapi.TextDocumentContentChangeEventDTO; | ||
import org.eclipse.che.plugin.languageserver.shared.lsapi.VersionedTextDocumentIdentifierDTO; | ||
|
||
import java.util.Collections; | ||
|
||
/** | ||
* Handles incremental text document update | ||
* | ||
* @author Evgen Vidolob | ||
*/ | ||
@Singleton | ||
class IncrementalTextDocumentSynchronize implements TextDocumentSynchronize { | ||
|
||
private final DtoFactory dtoFactory; | ||
private final TextDocumentServiceClient textDocumentService; | ||
|
||
@Inject | ||
public IncrementalTextDocumentSynchronize(DtoFactory dtoFactory, TextDocumentServiceClient textDocumentService) { | ||
this.dtoFactory = dtoFactory; | ||
this.textDocumentService = textDocumentService; | ||
} | ||
|
||
@Override | ||
public void syncTextDocument(DocumentChangeEvent event, int version) { | ||
Document document = event.getDocument().getDocument(); | ||
TextPosition startPosition = document.getPositionFromIndex(event.getOffset()); | ||
TextPosition endPosition; | ||
if (event.getRemoveCharCount() != 0) { | ||
endPosition = new TextPosition(startPosition.getLine(), startPosition.getCharacter() + event.getRemoveCharCount()); | ||
} else { | ||
endPosition = new TextPosition(startPosition.getLine(), startPosition.getCharacter() + event.getLength()); | ||
} | ||
|
||
DidChangeTextDocumentParamsDTO changeDTO = dtoFactory.createDto(DidChangeTextDocumentParamsDTO.class); | ||
String uri = document.getFile().getLocation().toString(); | ||
changeDTO.setUri(uri); | ||
VersionedTextDocumentIdentifierDTO versionedDocId = dtoFactory.createDto(VersionedTextDocumentIdentifierDTO.class); | ||
versionedDocId.setUri(uri); | ||
versionedDocId.setVersion(version); | ||
changeDTO.setTextDocument(versionedDocId); | ||
|
||
RangeDTO range = dtoFactory.createDto(RangeDTO.class); | ||
PositionDTO start = dtoFactory.createDto(PositionDTO.class); | ||
start.setLine(startPosition.getLine()); | ||
start.setCharacter(startPosition.getCharacter()); | ||
PositionDTO end = dtoFactory.createDto(PositionDTO.class); | ||
end.setLine(endPosition.getLine()); | ||
end.setCharacter(endPosition.getCharacter()); | ||
range.setStart(start); | ||
range.setEnd(end); | ||
|
||
TextDocumentContentChangeEventDTO actualChange = dtoFactory.createDto(TextDocumentContentChangeEventDTO.class); | ||
actualChange.setRange(range); | ||
actualChange.setText(event.getText()); | ||
|
||
changeDTO.setContentChanges(Collections.singletonList(actualChange)); | ||
textDocumentService.didChange(changeDTO); | ||
} | ||
} |
Oops, something went wrong.