Skip to content

Commit

Permalink
Merge pull request #2 from lostintangent/master
Browse files Browse the repository at this point in the history
Adding support for Visual Studio Live Share
  • Loading branch information
micnil committed Mar 11, 2018
2 parents 70ec50a + e0d0bdb commit 12f3cf3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
12 changes: 6 additions & 6 deletions src/CheckpointsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class CheckpointsController {
*/
private async onAddCheckpoint() {

if (this.activeEditor.document.isUntitled) {
if (this.activeEditor.document.uri.scheme === "untitled") {
console.log(`Failed to add file to store. Unsaved documents are currently not supported`);
window.showInformationMessage("Untitled documents are currently not supported");
return;
Expand Down Expand Up @@ -203,7 +203,7 @@ export class CheckpointsController {
if (textDocument.isUntitled) {
window.showInformationMessage(`Restored checkpoint '${checkpointNode.label}'`);
} else {
window.showInformationMessage(`Restored '${textDocument.fileName}' to checkpoint '${checkpointNode.label}'`);
window.showInformationMessage(`Restored '${checkpointNode.id}' to checkpoint '${checkpointNode.label}'`);
textDocument.save();
}
}
Expand All @@ -214,7 +214,7 @@ export class CheckpointsController {
}

// The file is not open in the currently active editor, open it.
if (success && checkpointNode.parentId !== this.model.checkpointContext.fsPath) {
if (success && checkpointNode.parentId !== this.model.checkpointContext.toString()) {
let editor = await window.showTextDocument(textDocument, {
preserveFocus: false,
preview: true,
Expand All @@ -229,7 +229,7 @@ export class CheckpointsController {
private onOpenFile(checkpointNode: CheckpointNode) {
console.log(`Opening file: '${checkpointNode.nodeId}'`);

workspace.openTextDocument(checkpointNode.nodeId).then(
workspace.openTextDocument(Uri.parse(checkpointNode.nodeId)).then(
// On success:
textDocument => {
window.showTextDocument(textDocument, {
Expand Down Expand Up @@ -287,7 +287,7 @@ export class CheckpointsController {
*/
private async onDiffWithCurrent(checkpointNode: CheckpointNode) {
try {
let textDocument = await workspace.openTextDocument(checkpointNode.parentId);
let textDocument = await workspace.openTextDocument(Uri.parse(checkpointNode.parentId));
this.documentView.showDiffWithDocument(textDocument.uri, checkpointNode.nodeId);
} catch (err) {
console.error(err);
Expand Down Expand Up @@ -337,7 +337,7 @@ export class CheckpointsController {
*/
private async openTextDocument(checkpoint: CheckpointNode) {
try{
return await workspace.openTextDocument(checkpoint.parentId);
return await workspace.openTextDocument(Uri.parse(checkpoint.parentId));
} catch (err) {
window.showWarningMessage("Failed to open original document, opening untitled document instead.")
return await workspace.openTextDocument({
Expand Down
4 changes: 2 additions & 2 deletions src/CheckpointsDocumentView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class CheckpointsDocumentView implements TextDocumentContentProvider {
return;
}
const checkpointUri = this.getCheckpointUri(checkpoint);
const comparingDocumentName = path.basename(checkpointUri.fsPath);
const comparingDocumentName = path.basename(checkpointUri.toString());
const diffTitle = `${comparingDocumentName}<->${checkpoint.name}`;
commands.executeCommand('vscode.diff', comparisonDocumentUri, checkpointUri, diffTitle);
}
Expand Down Expand Up @@ -115,7 +115,7 @@ export class CheckpointsDocumentView implements TextDocumentContentProvider {
* @param checkpoint The checkpoint
*/
private getCheckpointUri(checkpoint: ICheckpoint): Uri {
const filePath = Uri.file(checkpoint.parent);
const filePath = Uri.parse(checkpoint.parent);

// Set the checkpoint id to be the 'fragment' of the uri.
// The uri's 'path' part needs to be a file (fake or not) that has the
Expand Down
23 changes: 9 additions & 14 deletions src/CheckpointsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class CheckpointsModel {
// then return. We do not want to update the tree view in
// these cases because we loose selection marker unnecessarily.
if (this.currentCheckpointContext &&
(this.currentCheckpointContext.fsPath === fileUri.fsPath ||
(this.currentCheckpointContext.toString() === fileUri.toString() ||
fileUri.scheme === 'checkpointsDocumentView')) {
return;
}
Expand Down Expand Up @@ -171,19 +171,14 @@ export class CheckpointsModel {
* @param document The document to save
*/
add(document: TextDocument, name: string, timestamp: number): void {
console.log(`Adding file '${document.fileName}' to checkpoint store.`);
const documentId = document.uri.toString();
console.log(`Adding file '${documentId}' to checkpoint store.`);

// If there is no entry for this document, then create one
if (!this.checkpointStore.files.byId[document.fileName]) {

// Set file name and extra name (truncated relative path)

// First create an uri object of the file path
let fileUri = Uri.file(document.fileName);
// Get the relative path from workspace root to the file.
let relativeFilePath = workspace.asRelativePath(fileUri);
// If there is no entry for this document, then create one
if (!this.checkpointStore.files.byId[documentId]) {
// Remove the active file name and use as extra name.
let extraName = path.dirname(relativeFilePath);
let extraName = path.dirname(documentId);
// Truncate the name if it is too long
if (extraName.length > this.maxLengthFileName) {
extraName = '...' + extraName.substr(
Expand All @@ -192,11 +187,11 @@ export class CheckpointsModel {
);
}

let baseName = path.basename(document.fileName);
let baseName = path.basename(documentId);

// create the file
let file: IFile = {
id: document.fileName,
id: documentId,
name: baseName,
extraName: extraName,
fileNameDuplicates: [],
Expand All @@ -211,7 +206,7 @@ export class CheckpointsModel {

// create the checkpoint
let checkpoint: ICheckpoint = {
parent: document.fileName,
parent: documentId,
timestamp: timestamp,
text: document.getText(),
name: name,
Expand Down
6 changes: 3 additions & 3 deletions src/CheckpointsTreeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ export class CheckpointsTreeView implements TreeDataProvider<CheckpointNode> {
// Control the collapsed state of the file. We want it to expand when the file is selected
// and collapse when it is not selected.
element.collapsibleState =
this.model.checkpointContext.fsPath === file.id
this.model.checkpointContext.toString() === file.id
? TreeItemCollapsibleState.Expanded
: TreeItemCollapsibleState.Collapsed;

// Set the file icon
if (this.model.checkpointContext.fsPath === file.id) {
if (this.model.checkpointContext.toString() === file.id) {
element.iconPath = {
light: this.context.asAbsolutePath('resources/light/file-selected.svg'),
dark: this.context.asAbsolutePath('resources/dark/file-selected.svg'),
Expand Down Expand Up @@ -149,7 +149,7 @@ export class CheckpointsTreeView implements TreeDataProvider<CheckpointNode> {
// that belong to the currently active file only, return checkpoint
// nodes.
if (!element && showActiveFileOnly) {
let checkpoints = this.model.getCheckpoints(this.model.checkpointContext.fsPath);
let checkpoints = this.model.getCheckpoints(this.model.checkpointContext.toString());
return checkpoints.map(checkpoint => {
return new CheckpointNode(checkpoint.id, checkpoint.parent);
});
Expand Down

0 comments on commit 12f3cf3

Please sign in to comment.