Skip to content

Commit

Permalink
fix: missing callback in remote environments
Browse files Browse the repository at this point in the history
  • Loading branch information
sleistner committed Aug 8, 2019
1 parent b45bd6a commit 63ef29a
Show file tree
Hide file tree
Showing 20 changed files with 370 additions and 606 deletions.
38 changes: 38 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------

FROM node:8

# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive

# Configure apt and install packages
RUN apt-get update \
&& apt-get -y install --no-install-recommends apt-utils 2>&1 \
#
# Verify git and needed tools are installed
&& apt-get install -y git procps \
#
# Remove outdated yarn from /opt and install via package
# so it can be easily updated via apt-get upgrade yarn
&& rm -rf /opt/yarn-* \
&& rm -f /usr/local/bin/yarn \
&& rm -f /usr/local/bin/yarnpkg \
&& apt-get install -y curl apt-transport-https lsb-release \
&& curl -sS https://dl.yarnpkg.com/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/pubkey.gpg | apt-key add - 2>/dev/null \
&& echo "deb https://dl.yarnpkg.com/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& apt-get update \
&& apt-get -y install --no-install-recommends yarn \
#
# Install tslint and typescript globally
&& npm install -g tslint typescript \
#
# Clean up
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=dialog
18 changes: 18 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// See https://aka.ms/vscode-remote/devcontainer.json for format details.
{
"name": "Node.js 8 & TypeScript",
"dockerFile": "Dockerfile",

// Uncomment the next line if you want to publish any ports.
// "appPort": [],

// Uncomment the next line if you want to add in default container specific settings.json values
// "settings": { "workbench.colorTheme": "Quiet Light" },

// Uncomment the next line to run commands after the container is created.
// "postCreateCommand": "yarn install",

"extensions": [
"ms-vscode.vscode-typescript-tslint-plugin"
]
}
13 changes: 6 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sudo: false
language: node_js

node_js:
- '8'
- "8"

os:
- osx
Expand All @@ -16,10 +16,10 @@ stages:

before_install:
- if [ $TRAVIS_OS_NAME == "linux" ]; then
export CXX="g++-4.9" CC="gcc-4.9" DISPLAY=:99.0;
sudo apt-get --assume-yes install libsecret-1-0 xclip;
sh -e /etc/init.d/xvfb start;
sleep 3;
export CXX="g++-4.9" CC="gcc-4.9" DISPLAY=:99.0;
sudo apt-get --assume-yes install libsecret-1-0 xclip;
sh -e /etc/init.d/xvfb start;
sleep 3;
fi

install:
Expand All @@ -28,11 +28,10 @@ install:

script:
- npm run lint --silent
- npm test --silent
- npm test

jobs:
include:
- stage: release
os: linux
script: npm run semantic-release

12 changes: 3 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"name": "vscode-fileutils",
"displayName": "File Utils",
"description": "A convenient way of creating, duplicating, moving, renaming and deleting files and directories.",
"version": "2.13.5",
"version": "2.14.5",
"license": "MIT",
"publisher": "sleistner",
"engines": {
"vscode": "^1.20.0"
"vscode": "^1.30.0"
},
"categories": [
"Other"
Expand Down Expand Up @@ -205,7 +205,7 @@
"tslint": "^5.9.1",
"tslint-no-unused-expression-chai": "^0.1.4",
"typescript": "^3.0.3",
"vscode": "^1.1.26"
"vscode": "^1.1.36"
},
"dependencies": {
"bluebird-retry": "^0.11.0",
Expand All @@ -214,8 +214,7 @@
"gitignore-to-glob": "github:patbenatar/gitignore-to-glob",
"bluebird": "^3.5.1",
"trash": "^5.0.0",
"fs-extra": "^8.0.0",
"copy-paste-win32fix": "^1.4.0"
"fs-extra": "^8.0.0"
},
"pre-commit": [
"lint",
Expand Down
52 changes: 0 additions & 52 deletions src/ClipboardUtil.ts

This file was deleted.

28 changes: 18 additions & 10 deletions src/Item.ts → src/FileItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,43 @@ export class FileItem {
}

public async move(): Promise<FileItem> {
await this.ensureDir();
await fs.rename(this.path, this.targetPath);
this.ensureDir();
fs.renameSync(this.path, this.targetPath);

this.SourcePath = this.targetPath;
return this;
}

public async duplicate(): Promise<FileItem> {
await this.ensureDir();
await fs.copy(this.path, this.targetPath);
this.ensureDir();
fs.copySync(this.path, this.targetPath);

return new FileItem(this.targetPath);
}

public async remove(useTrash = false): Promise<FileItem> {
await useTrash ? trash(this.path) : fs.remove(this.path);
if (useTrash) {
await trash(this.path);
} else {
fs.removeSync(this.path);
}

return this;
}

public async create(mkDir?: boolean): Promise<FileItem> {
const fn = mkDir === true || this.isDir ? fs.ensureDir : fs.createFile;
await fs.remove(this.targetPath);
await fn(this.targetPath);
fs.removeSync(this.targetPath);

if (mkDir === true || this.isDir) {
fs.ensureDirSync(this.targetPath);
} else {
fs.createFileSync(this.targetPath);
}

return new FileItem(this.targetPath);
}

private async ensureDir(): Promise<any> {
return fs.ensureDir(path.dirname(this.targetPath));
private ensureDir() {
return fs.ensureDirSync(path.dirname(this.targetPath));
}
}
13 changes: 6 additions & 7 deletions src/controller/BaseFileController.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { IDialogOptions, IExecuteOptions, IFileController } from './FileController';

import * as fs from 'fs';
import { commands, TextDocument, TextEditor, ViewColumn, window, workspace } from 'vscode';
import { ClipboardUtil } from '../ClipboardUtil';
import { FileItem } from '../Item';
import { commands, env, TextEditor, ViewColumn, window, workspace } from 'vscode';
import { FileItem } from '../FileItem';

export abstract class BaseFileController implements IFileController {
public abstract async showDialog(options?: IDialogOptions): Promise<FileItem>;
Expand Down Expand Up @@ -70,21 +69,21 @@ export abstract class BaseFileController implements IFileController {
private async getSourcePathForNonTextFile(): Promise<string> {
// Since there is no API to get details of non-textual files, the following workaround is performed:
// 1. Saving the original clipboard data to a local variable.
const originalClipboardData = await ClipboardUtil.getClipboardContent();
const originalClipboardData = await env.clipboard.readText();

// 2. Populating the clipboard with an empty string
await ClipboardUtil.setClipboardContent('');
await env.clipboard.writeText('');

// 3. Calling the copyPathOfActiveFile that populates the clipboard with the source path of the active file.
// If there is no active file - the clipboard will not be populated and it will stay with the empty string.
await commands.executeCommand('workbench.action.files.copyPathOfActiveFile');

// 4. Get the clipboard data after the API call
const postAPICallClipboardData = await ClipboardUtil.getClipboardContent();
const postAPICallClipboardData = await await env.clipboard.readText();

// 5. Return the saved original clipboard data to the clipboard so this method
// will not interfere with the clipboard's content.
await ClipboardUtil.setClipboardContent(originalClipboardData);
await env.clipboard.writeText(originalClipboardData);

// 6. Return the clipboard data from the API call (which could be an empty string if it failed).
return postAPICallClipboardData;
Expand Down
7 changes: 3 additions & 4 deletions src/controller/CopyFileNameController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Uri } from 'vscode';
import { ClipboardUtil } from '../ClipboardUtil';
import { FileItem } from '../Item';
import { env, Uri } from 'vscode';
import { FileItem } from '../FileItem';
import { BaseFileController } from './BaseFileController';
import { IDialogOptions, IExecuteOptions } from './FileController';

Expand All @@ -20,7 +19,7 @@ export class CopyFileNameController extends BaseFileController {
}

public async execute(options: IExecuteOptions): Promise<FileItem> {
await ClipboardUtil.setClipboardContent(options.fileItem.name);
await env.clipboard.writeText(options.fileItem.name);
return options.fileItem;
}
}
2 changes: 1 addition & 1 deletion src/controller/DuplicateFileController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FileItem } from '../Item';
import { FileItem } from '../FileItem';
import { IExecuteOptions } from './FileController';
import { MoveFileController } from './MoveFileController';

Expand Down
2 changes: 1 addition & 1 deletion src/controller/FileController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TextEditor } from 'vscode';
import { FileItem } from '../Item';
import { FileItem } from '../FileItem';

export interface IDialogOptions {
prompt?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/controller/MoveFileController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';
import { Uri, window } from 'vscode';
import { FileItem } from '../Item';
import { FileItem } from '../FileItem';
import { BaseFileController } from './BaseFileController';
import { IDialogOptions, IExecuteOptions } from './FileController';

Expand Down
2 changes: 1 addition & 1 deletion src/controller/NewFileController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';
import { Uri, window, workspace, WorkspaceFolder } from 'vscode';
import { FileItem } from '../Item';
import { FileItem } from '../FileItem';
import { getConfiguration } from '../lib/config';
import { BaseFileController } from './BaseFileController';
import { IDialogOptions, IExecuteOptions } from './FileController';
Expand Down
2 changes: 1 addition & 1 deletion src/controller/RemoveFileController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';
import { window } from 'vscode';
import { FileItem } from '../Item';
import { FileItem } from '../FileItem';
import { getConfiguration } from '../lib/config';
import { BaseFileController } from './BaseFileController';
import { IExecuteOptions } from './FileController';
Expand Down
Loading

0 comments on commit 63ef29a

Please sign in to comment.