Enable strict mode for many samples

This commit is contained in:
Matt Bierner
2019-05-10 14:34:54 -07:00
parent 9974850d29
commit 03cf5fa9f1
40 changed files with 155 additions and 96 deletions

View File

@ -5,7 +5,8 @@
"outDir": "out",
"lib": ["es6"],
"sourceMap": true,
"rootDir": "src"
"rootDir": "src",
"strict": true
},
"exclude": ["node_modules", ".vscode-test"]
}

View File

@ -17,7 +17,7 @@ export function activate(context: ExtensionContext) {
context.subscriptions.push(workspace.onDidChangeWorkspaceFolders(e => updateStatus(status)));
// Update status bar item based on events for configuration
context.subscriptions.push(workspace.onDidChangeConfiguration(e => this.updateStatus(status)));
context.subscriptions.push(workspace.onDidChangeConfiguration(e => updateStatus(status)));
// Update status bar item based on events around the active editor
context.subscriptions.push(window.onDidChangeActiveTextEditor(e => updateStatus(status)));
@ -30,9 +30,9 @@ export function activate(context: ExtensionContext) {
function updateStatus(status: StatusBarItem): void {
const info = getEditorInfo();
status.text = info ? info.text : void 0;
status.tooltip = info ? info.tooltip : void 0;
status.color = info ? info.color : void 0;
status.text = info ? info.text || '' : '';
status.tooltip = info ? info.tooltip : undefined;
status.color = info ? info.color : undefined;
if (info) {
status.show();
@ -41,7 +41,7 @@ function updateStatus(status: StatusBarItem): void {
}
}
function getEditorInfo(): { text: string; tooltip: string; color: string; } {
function getEditorInfo(): { text?: string; tooltip?: string; color?: string; } | null {
const editor = window.activeTextEditor;
// If no workspace is opened or just a single folder, we return without any status label
@ -50,9 +50,9 @@ function getEditorInfo(): { text: string; tooltip: string; color: string; } {
return null;
}
let text: string;
let tooltip: string;
let color: string;
let text: string | undefined;
let tooltip: string | undefined;
let color: string | undefined;
// If we have a file:// resource we resolve the WorkspaceFolder this file is from and update
// the status accordingly.

View File

@ -5,7 +5,8 @@
"outDir": "out",
"lib": ["es6"],
"sourceMap": true,
"rootDir": "."
"rootDir": ".",
"strict": true
},
"exclude": ["node_modules", ".vscode-test"]
}

View File

@ -5,6 +5,7 @@
"outDir": "out",
"lib": ["es6"],
"sourceMap": true,
"strict": true,
"rootDir": "src"
},
"exclude": ["node_modules", ".vscode-test"]

View File

@ -7,6 +7,7 @@
"es6"
],
"sourceMap": true,
"strict": true,
"rootDir": "src"
},
"exclude": [

View File

@ -61,10 +61,10 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.workspace.onDidOpenTextDocument(e => {
// 1) Get the configured glob pattern value for the current file
const value = vscode.workspace.getConfiguration('', e.uri).get('conf.resource.insertEmptyLastLine');
const value: any = vscode.workspace.getConfiguration('', e.uri).get('conf.resource.insertEmptyLastLine');
// 2) Check if the current resource matches the glob pattern
const matches = value[e.fileName];
const matches = value ? value[e.fileName] : undefined;
// 3) If matches, insert empty last line
if (matches) {
@ -91,9 +91,8 @@ export function activate(context: vscode.ExtensionContext) {
const value = { ...currentValue, ...{ [currentDocument.fileName]: true } };
// 4) Update the configuration
await configuration.update('conf.resource.insertEmptyLastLine', value, target)
await configuration.update('conf.resource.insertEmptyLastLine', value, target);
}
});
// Example 5: Updating Resource scoped Configuration
@ -118,7 +117,7 @@ export function activate(context: vscode.ExtensionContext) {
if (target.target === vscode.ConfigurationTarget.WorkspaceFolder) {
// 3) Getting the workspace folder
let workspaceFolder = await vscode.window.showWorkspaceFolderPick({ placeHolder: 'Pick Workspace Folder to which this setting should be applied' })
let workspaceFolder = await vscode.window.showWorkspaceFolderPick({ placeHolder: 'Pick Workspace Folder to which this setting should be applied' });
if (workspaceFolder) {
// 4) Get the configuration for the workspace folder
@ -140,7 +139,7 @@ export function activate(context: vscode.ExtensionContext) {
// 4) Get the current value
const currentValue = configuration.get('conf.resource.insertEmptyLastLine');
const newValue = { ...currentValue, ...{ [value]: true } };
const newValue = { ...currentValue, ...(value ? { [value]: true } : {}) };
// 3) Update the value in the target
await vscode.workspace.getConfiguration().update('conf.resource.insertEmptyLastLine', newValue, target.target);
@ -154,7 +153,7 @@ export function activate(context: vscode.ExtensionContext) {
// 3) Get the current value
const currentValue = configuration.get('conf.resource.insertEmptyLastLine');
const newValue = { ...currentValue, ...{ [value]: true } };
const newValue = { ...currentValue, ...(value ? { [value]: true } : {}) };
// 4) Update the value in the User Settings
await vscode.workspace.getConfiguration().update('conf.resource.insertEmptyLastLine', newValue, vscode.ConfigurationTarget.Global);
@ -170,7 +169,7 @@ export function activate(context: vscode.ExtensionContext) {
const currentDocument = vscode.window.activeTextEditor.document;
// 1) Get the configured glob pattern value for the current file
const value = vscode.workspace.getConfiguration('', currentDocument.uri).get('conf.resource.insertEmptyLastLine');
const value: any = vscode.workspace.getConfiguration('', currentDocument.uri).get('conf.resource.insertEmptyLastLine');
// 2) Check if the current resource matches the glob pattern
const matches = value[currentDocument.fileName];

View File

@ -7,6 +7,7 @@
"es6"
],
"sourceMap": true,
"strict": true,
"rootDir": "src"
},
"exclude": [

View File

@ -21,7 +21,7 @@ export function activate(context: ExtensionContext) {
// open the dynamic document, and shows it in the next editor
const commandRegistration = commands.registerTextEditorCommand('editor.printReferences', editor => {
const uri = encodeLocation(editor.document.uri, editor.selection.active);
return workspace.openTextDocument(uri).then(doc => window.showTextDocument(doc, editor.viewColumn + 1));
return workspace.openTextDocument(uri).then(doc => window.showTextDocument(doc, editor.viewColumn! + 1));
});
context.subscriptions.push(

View File

@ -52,10 +52,11 @@ export default class Provider implements vscode.TextDocumentContentProvider, vsc
// printing, and formatting references
const [target, pos] = decodeLocation(uri);
return vscode.commands.executeCommand<vscode.Location[]>('vscode.executeReferenceProvider', target, pos).then(locations => {
locations = locations || [];
// sort by locations and shuffle to begin from target resource
let idx = 0;
locations.sort(Provider._compareLocations).find((loc, i) => loc.uri.toString() === target.toString() && (idx = i) && true);
locations.sort(Provider._compareLocations).find((loc, i) => loc.uri.toString() === target.toString() && !!(idx = i) && true);
locations.push(...locations.splice(0, idx));
// create document and return its early state
@ -71,11 +72,11 @@ export default class Provider implements vscode.TextDocumentContentProvider, vsc
} else if (a.uri.toString() > b.uri.toString()) {
return 1;
} else {
return a.range.start.compareTo(b.range.start)
return a.range.start.compareTo(b.range.start);
}
}
provideDocumentLinks(document: vscode.TextDocument, token: vscode.CancellationToken): vscode.DocumentLink[] {
provideDocumentLinks(document: vscode.TextDocument, token: vscode.CancellationToken): vscode.DocumentLink[] | undefined {
// While building the virtual document we have already created the links.
// Those are composed from the range inside the document and a target uri
// to which they point

View File

@ -13,7 +13,7 @@ export default class ReferencesDocument {
private _lines: string[];
private _links: vscode.DocumentLink[];
private _join: Thenable<this>;
private _join?: Thenable<this>;
constructor(uri: vscode.Uri, locations: vscode.Location[], emitter: vscode.EventEmitter<vscode.Uri>) {
this._uri = uri;
@ -37,7 +37,7 @@ export default class ReferencesDocument {
return this._links;
}
join(): Thenable<this> {
join(): Thenable<this> | undefined {
return this._join;
}
@ -81,7 +81,7 @@ export default class ReferencesDocument {
this._emitter.fire(this._uri);
next();
});
}
};
next();
});
}

View File

@ -5,6 +5,7 @@
"outDir": "out",
"lib": ["es6"],
"sourceMap": true,
"strict": true,
"rootDir": "src"
},
"exclude": ["node_modules"]

View File

@ -5,6 +5,7 @@
"outDir": "out",
"lib": ["es6"],
"sourceMap": true,
"strict": true,
"rootDir": "src"
},
"exclude": ["node_modules", ".vscode-test"]

View File

@ -8,8 +8,11 @@ export function activate(context: vscode.ExtensionContext) {
if (vscode.window.activeTextEditor) {
updateDiagnostics(vscode.window.activeTextEditor.document, collection);
}
context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(e => updateDiagnostics(e.document, collection)));
context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(editor => {
if (editor) {
updateDiagnostics(editor.document, collection);
}
}));
}
function updateDiagnostics(document: vscode.TextDocument, collection: vscode.DiagnosticCollection): void {

View File

@ -7,6 +7,7 @@
"es6"
],
"sourceMap": true,
"strict": true,
"rootDir": "src"
},
"exclude": [

View File

@ -5,6 +5,7 @@
"outDir": "out",
"lib": ["es6"],
"sourceMap": true,
"strict": true,
"rootDir": "src"
},
"exclude": ["node_modules", ".vscode-test"]

View File

@ -16,7 +16,7 @@ export class File implements vscode.FileStat {
size: number;
name: string;
data: Uint8Array;
data?: Uint8Array;
constructor(name: string) {
this.type = vscode.FileType.File;
@ -71,7 +71,11 @@ export class MemFS implements vscode.FileSystemProvider {
// --- manage file contents
readFile(uri: vscode.Uri): Uint8Array {
return this._lookupAsFile(uri, false).data;
const data = this._lookupAsFile(uri, false).data;
if (data) {
return data;
}
throw vscode.FileSystemError.FileNotFound();
}
writeFile(uri: vscode.Uri, content: Uint8Array, options: { create: boolean, overwrite: boolean }): void {
@ -200,18 +204,22 @@ export class MemFS implements vscode.FileSystemProvider {
private _emitter = new vscode.EventEmitter<vscode.FileChangeEvent[]>();
private _bufferedEvents: vscode.FileChangeEvent[] = [];
private _fireSoonHandle: NodeJS.Timer;
private _fireSoonHandle?: NodeJS.Timer;
readonly onDidChangeFile: vscode.Event<vscode.FileChangeEvent[]> = this._emitter.event;
watch(resource: vscode.Uri, opts): vscode.Disposable {
watch(_resource: vscode.Uri): vscode.Disposable {
// ignore, fires for all changes...
return new vscode.Disposable(() => { });
}
private _fireSoon(...events: vscode.FileChangeEvent[]): void {
this._bufferedEvents.push(...events);
clearTimeout(this._fireSoonHandle);
if (this._fireSoonHandle) {
clearTimeout(this._fireSoonHandle);
}
this._fireSoonHandle = setTimeout(() => {
this._emitter.fire(this._bufferedEvents);
this._bufferedEvents.length = 0;

View File

@ -6,6 +6,7 @@
"outDir": "out",
"lib": ["es6"],
"sourceMap": true,
"strict": true,
"rootDir": "."
},
"exclude": ["node_modules", ".vscode-test"]

View File

@ -5,6 +5,7 @@
"outDir": "out",
"lib": ["es6"],
"sourceMap": true,
"strict": true,
"rootDir": "src"
},
"exclude": ["node_modules", ".vscode-test"]

View File

@ -5,6 +5,7 @@
"outDir": "out",
"lib": ["es6"],
"sourceMap": true,
"strict": true,
"rootDir": "src"
},
"exclude": ["node_modules", ".vscode-test"]

View File

@ -19,12 +19,12 @@ let client: LanguageClient;
export function activate(context: ExtensionContext) {
const socketPort = workspace.getConfiguration('languageServerExample').get('port', 7000);
let socket: WebSocket | null = null
let socket: WebSocket | null = null;
commands.registerCommand('languageServerExample.startStreaming', () => {
// Establish websocket connection
socket = new WebSocket(`ws://localhost:${socketPort}`)
})
socket = new WebSocket(`ws://localhost:${socketPort}`);
});
// The server is implemented in node
let serverModule = context.asAbsolutePath(
@ -46,27 +46,27 @@ export function activate(context: ExtensionContext) {
};
// The log to send
let log = ''
let log = '';
const websocketOutputChannel: OutputChannel = {
name: 'websocket',
// Only append the logs but send them later
append(value: string) {
log += value
console.log(value)
log += value;
console.log(value);
},
appendLine(value: string) {
log += value
log += value;
// Don't send logs until WebSocket initialization
if (socket && socket.readyState === WebSocket.OPEN) {
socket.send(log)
socket.send(log);
}
log = ''
log = '';
},
clear() {},
show() {},
hide() {},
dispose() {}
}
};
// Options to control the language client
let clientOptions: LanguageClientOptions = {

View File

@ -36,13 +36,13 @@ connection.onInitialize((params: InitializeParams) => {
// Does the client support the `workspace/configuration` request?
// If not, we will fall back using global settings
hasConfigurationCapability =
capabilities.workspace && !!capabilities.workspace.configuration;
!!capabilities.workspace && !!capabilities.workspace.configuration;
hasWorkspaceFolderCapability =
capabilities.workspace && !!capabilities.workspace.workspaceFolders;
hasDiagnosticRelatedInformationCapability =
!!capabilities.workspace && !!capabilities.workspace.workspaceFolders;
hasDiagnosticRelatedInformationCapability = !!(
capabilities.textDocument &&
capabilities.textDocument.publishDiagnostics &&
capabilities.textDocument.publishDiagnostics.relatedInformation;
capabilities.textDocument.publishDiagnostics.relatedInformation);
return {
capabilities: {
@ -131,7 +131,7 @@ async function validateTextDocument(textDocument: TextDocument): Promise<void> {
// The validator creates diagnostics for all uppercase words length 2 and more
let text = textDocument.getText();
let pattern = /\b[A-Z]{2,}\b/g;
let m: RegExpExecArray;
let m: RegExpExecArray | null;
let problems = 0;
let diagnostics: Diagnostic[] = [];

View File

@ -5,6 +5,7 @@
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"strict": true,
"outDir": "out",
"rootDir": "src",
"lib": ["es6"]

View File

@ -4,6 +4,7 @@
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"strict": true,
"outDir": "out",
"rootDir": "src",
"lib": ["es6"]

View File

@ -5,6 +5,7 @@
"outDir": "out",
"lib": ["es6"],
"sourceMap": true,
"strict": true,
"rootDir": "src"
},
"exclude": ["node_modules"]

View File

@ -30,7 +30,7 @@
"devDependencies": {
"@types/node": "10.3.6",
"tslint": "^5.16.0",
"typescript": "2.9.2",
"typescript": "^3.4.5",
"@types/vscode": "^1.32.0"
}
}

View File

@ -49,7 +49,7 @@ export function activate(context: vscode.ExtensionContext) {
}));
}
async function pickSourceControl(): Promise<FiddleSourceControl> {
async function pickSourceControl(): Promise<FiddleSourceControl | undefined> {
// todo: when/if the SourceControl exposes a 'selected' property, use that instead
if (fiddleSourceControlRegister.size == 0) return undefined;
@ -85,13 +85,13 @@ async function tryOpenFiddle(context: vscode.ExtensionContext, fiddleId?: string
}
async function openFiddle(context: vscode.ExtensionContext, fiddleId?: string, workspaceUri?: vscode.Uri) {
if (fiddleSourceControlRegister.has(workspaceUri)) vscode.window.showErrorMessage("Another Fiddle was already open in this workspace. Open a new workspace first.");
if (workspaceUri && fiddleSourceControlRegister.has(workspaceUri)) vscode.window.showErrorMessage("Another Fiddle was already open in this workspace. Open a new workspace first.");
if (!fiddleId) {
fiddleId = await vscode.window.showInputBox({ prompt: 'Paste JSFiddle ID and optionally version', placeHolder: 'slug or slug/version, e.g. u8B29/1', value: 'demo' });
fiddleId = (await vscode.window.showInputBox({ prompt: 'Paste JSFiddle ID and optionally version', placeHolder: 'slug or slug/version, e.g. u8B29/1', value: 'demo' })) || '';
}
let workspaceFolder: vscode.WorkspaceFolder =
let workspaceFolder =
workspaceUri ?
vscode.workspace.getWorkspaceFolder(workspaceUri) :
await selectWorkspaceFolder(context, fiddleId);
@ -122,7 +122,7 @@ function registerFiddleSourceControl(fiddleSourceControl: FiddleSourceControl, c
if (fiddleSourceControlRegister.has(fiddleSourceControl.getWorkspaceFolder().uri)) {
// the folder was already under source control
let previousSourceControl = fiddleSourceControlRegister.get(fiddleSourceControl.getWorkspaceFolder().uri);
const previousSourceControl = fiddleSourceControlRegister.get(fiddleSourceControl.getWorkspaceFolder().uri)!;
previousSourceControl.dispose();
}
@ -135,7 +135,7 @@ function initializeFromConfigurationFile(context: vscode.ExtensionContext): void
if (!vscode.workspace.workspaceFolders) return;
vscode.workspace.workspaceFolders.forEach(folder => {
let configurationPath = path.join(folder.uri.fsPath, CONFIGURATION_FILE);
const configurationPath = path.join(folder.uri.fsPath, CONFIGURATION_FILE);
exists(configurationPath, configFileExists => {
if (configFileExists) {
readFile(configurationPath, { flag: 'r' }, async (err, data) => {
@ -152,16 +152,16 @@ function initializeFromConfigurationFile(context: vscode.ExtensionContext): void
});
}
async function selectWorkspaceFolder(context: vscode.ExtensionContext, fiddleId: string): Promise<vscode.WorkspaceFolder> {
var selectedFolder: vscode.WorkspaceFolder;
var workspaceFolderUri: vscode.Uri;
var workspaceFolderIndex: number;
async function selectWorkspaceFolder(context: vscode.ExtensionContext, fiddleId: string): Promise<vscode.WorkspaceFolder | undefined> {
var selectedFolder: vscode.WorkspaceFolder | undefined;
var workspaceFolderUri: vscode.Uri | undefined;
var workspaceFolderIndex: number | undefined;
const fiddleConfiguration = parseFiddleId(fiddleId);
if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 1) {
selectedFolder = await vscode.window.showWorkspaceFolderPick({ placeHolder: 'Pick workspace folder to create files in.' });
if (!selectedFolder) return null;
if (!selectedFolder) return undefined;
workspaceFolderIndex = selectedFolder.index;
workspaceFolderUri = selectedFolder.uri;
@ -169,41 +169,43 @@ async function selectWorkspaceFolder(context: vscode.ExtensionContext, fiddleId:
else if (!vscode.workspace.workspaceFolders) {
let folderUris = await vscode.window.showOpenDialog({ canSelectFolders: true, canSelectFiles: false, canSelectMany: false, openLabel: 'Select folder' });
if (!folderUris) {
return null;
return undefined;
}
workspaceFolderUri = folderUris[0];
// was such workspace folder already open?
workspaceFolderIndex = vscode.workspace.workspaceFolders && firstIndex(vscode.workspace.workspaceFolders, folder1 => folder1.uri.toString() === workspaceFolderUri.toString());
workspaceFolderIndex = vscode.workspace.workspaceFolders && firstIndex(vscode.workspace.workspaceFolders, (folder1: any) => folder1.uri.toString() === workspaceFolderUri!.toString());
// save folder configuration
FiddleSourceControl.saveConfiguration(workspaceFolderUri, fiddleConfiguration);
selectedFolder = null; // the extension will get reloaded in the context of the newly open workspace
selectedFolder = undefined; // the extension will get reloaded in the context of the newly open workspace
}
else {
selectedFolder = vscode.workspace.workspaceFolders[0];
}
let workSpacesToReplace = workspaceFolderIndex > -1 ? 1 : 0;
let workSpacesToReplace = typeof workspaceFolderIndex === 'number' && workspaceFolderIndex > -1 ? 1 : 0;
if (workspaceFolderIndex === undefined || workspaceFolderIndex < 0) workspaceFolderIndex = 0;
// replace or insert the workspace
vscode.workspace.updateWorkspaceFolders(workspaceFolderIndex, workSpacesToReplace, { uri: workspaceFolderUri });
if (workspaceFolderUri) {
vscode.workspace.updateWorkspaceFolders(workspaceFolderIndex, workSpacesToReplace, { uri: workspaceFolderUri });
}
return selectedFolder;
}
async function clearWorkspaceFolder(workspaceFolder: vscode.WorkspaceFolder): Promise<vscode.WorkspaceFolder> {
async function clearWorkspaceFolder(workspaceFolder?: vscode.WorkspaceFolder): Promise<vscode.WorkspaceFolder | undefined> {
if (!workspaceFolder) return null;
if (!workspaceFolder) return undefined;
// check if the workspace is empty, or clear it
let existingWorkspaceFiles = readdirSync(workspaceFolder.uri.fsPath);
if (existingWorkspaceFiles.length > 0) {
let answer = await vscode.window.showQuickPick(["Yes", "No"],
{ placeHolder: `Remove ${existingWorkspaceFiles.length} file(s) from the workspace before cloning the remote repository?` });
if (answer === undefined) return null;
if (answer === undefined) return undefined;
if (answer === "Yes") {
existingWorkspaceFiles

View File

@ -1,6 +1,6 @@
export class FiddleConfiguration {
export interface FiddleConfiguration {
readonly slug: string;
readonly version: number;
readonly version?: number;
}
export function parseFiddleId(id: string): FiddleConfiguration {

View File

@ -63,7 +63,7 @@ const DEMO: FiddleData[] = [
];
// emulates prior versions mock-committed in previous sessions
var demoVersionOffset: number = undefined;
var demoVersionOffset: number | undefined = undefined;
export async function downloadFiddle(slug: string, version: number | undefined): Promise<Fiddle> {
@ -99,7 +99,7 @@ export async function downloadFiddle(slug: string, version: number | undefined):
});
}
export async function uploadFiddle(slug: string, version: number, html: string, js: string, css: string): Promise<Fiddle> {
export async function uploadFiddle(slug: string, version: number, html: string, js: string, css: string): Promise<Fiddle | undefined> {
if (slug === "demo") {
// using mock fiddle

View File

@ -12,8 +12,8 @@ export class FiddleSourceControl implements vscode.Disposable {
private fiddleRepository: FiddleRepository;
private latestFiddleVersion: number = Number.POSITIVE_INFINITY; // until actual value is established
private _onRepositoryChange = new vscode.EventEmitter<Fiddle>();
private timeout: NodeJS.Timer;
private fiddle: Fiddle;
private timeout?: NodeJS.Timer;
private fiddle!: Fiddle;
constructor(context: vscode.ExtensionContext, private readonly workspaceFolder: vscode.WorkspaceFolder, fiddle: Fiddle, overwrite: boolean) {
this.jsFiddleScm = vscode.scm.createSourceControl('jsfiddle', 'JSFiddle #' + fiddle.slug, workspaceFolder.uri);
@ -211,7 +211,7 @@ export class FiddleSourceControl implements vscode.Disposable {
async establishVersion(): Promise<void> {
let version = 0;
let latestVersion = Number.NaN;
let currentFiddle: Fiddle = undefined;
let currentFiddle: Fiddle | undefined = undefined;
while (true) {
try {
let latestFiddle = await downloadFiddle(this.fiddle.slug, version);
@ -229,7 +229,9 @@ export class FiddleSourceControl implements vscode.Disposable {
this.latestFiddleVersion = latestVersion;
// now we know the version of the current fiddle, let's set it
this.setFiddle(currentFiddle, false);
if (currentFiddle) {
this.setFiddle(currentFiddle, false);
}
}

View File

@ -6,8 +6,8 @@
"lib": [
"es6"
],
"strict": true,
"sourceMap": true,
"strict": true,
"rootDir": "src"
},
"exclude": [

View File

@ -5,6 +5,7 @@
"outDir": "out",
"lib": ["es6"],
"sourceMap": true,
"strict": true,
"rootDir": "src"
},
"include": ["src"],

View File

@ -13,7 +13,7 @@ export function activate(context: vscode.ExtensionContext) {
vscode.window.onDidOpenTerminal(terminal => {
console.log("Terminal opened. Total count: " + (<any>vscode.window).terminals.length);
(<any>terminal).onDidWriteData(data => {
(<any>terminal).onDidWriteData((data: any) => {
console.log("Terminal data: ", data);
});
});
@ -42,31 +42,51 @@ export function activate(context: vscode.ExtensionContext) {
// Terminal.hide
context.subscriptions.push(vscode.commands.registerCommand('terminalTest.hide', () => {
if (ensureTerminalExists()) {
selectTerminal().then(terminal => terminal.hide());
selectTerminal().then(terminal => {
if (terminal) {
terminal.hide();
}
});
}
}));
// Terminal.show
context.subscriptions.push(vscode.commands.registerCommand('terminalTest.show', () => {
if (ensureTerminalExists()) {
selectTerminal().then(terminal => terminal.show());
selectTerminal().then(terminal => {
if (terminal) {
terminal.show();
}
});
}
}));
context.subscriptions.push(vscode.commands.registerCommand('terminalTest.showPreserveFocus', () => {
if (ensureTerminalExists()) {
selectTerminal().then(terminal => terminal.show(true));
selectTerminal().then(terminal => {
if (terminal) {
terminal.show(true);
}
});
}
}));
// Terminal.sendText
context.subscriptions.push(vscode.commands.registerCommand('terminalTest.sendText', () => {
if (ensureTerminalExists()) {
selectTerminal().then(terminal => terminal.sendText("echo 'Hello world!'"));
selectTerminal().then(terminal => {
if (terminal) {
terminal.sendText("echo 'Hello world!'");
}
});
}
}));
context.subscriptions.push(vscode.commands.registerCommand('terminalTest.sendTextNoNewLine', () => {
if (ensureTerminalExists()) {
selectTerminal().then(terminal => terminal.sendText("echo 'Hello world!'", false));
selectTerminal().then(terminal => {
if (terminal) {
terminal.sendText("echo 'Hello world!'", false);
}
});
}
}));
@ -84,6 +104,9 @@ export function activate(context: vscode.ExtensionContext) {
// Terminal.processId
context.subscriptions.push(vscode.commands.registerCommand('terminalTest.processId', () => {
selectTerminal().then(terminal => {
if (!terminal) {
return;
}
terminal.processId.then((processId) => {
if (processId) {
vscode.window.showInformationMessage(`Terminal.processId: ${processId}`);
@ -109,6 +132,9 @@ export function activate(context: vscode.ExtensionContext) {
// vscode.window.onDidWriteData
context.subscriptions.push(vscode.commands.registerCommand('terminalTest.onDidWriteData', () => {
selectTerminal().then(terminal => {
if (!terminal) {
return;
}
vscode.window.showInformationMessage(`onDidWriteData listener attached for terminal: ${terminal.name}, check the devtools console to see events`);
(<any>terminal).onDidWriteData((data: string) => {
console.log('onDidWriteData: ' + data);
@ -119,16 +145,16 @@ export function activate(context: vscode.ExtensionContext) {
// vscode.window.onDidChangeTerminalDimensions
context.subscriptions.push(vscode.commands.registerCommand('terminalTest.onDidChangeTerminalDimensions', () => {
vscode.window.showInformationMessage(`Listening to onDidChangeTerminalDimensions, check the devtools console to see events`);
(<any>vscode.window).onDidChangeTerminalDimensions((event) => {
(<any>vscode.window).onDidChangeTerminalDimensions((event: any) => {
console.log(`onDidChangeTerminalDimensions: terminal:${event.terminal.name}, columns=${event.dimensions.columns}, rows=${event.dimensions.rows}`);
});
}));
let renderer;
let renderer: any | undefined;
context.subscriptions.push(vscode.commands.registerCommand('terminalTest.terminalRendererCreate', () => {
renderer = (<any>vscode.window).createTerminalRenderer('renderer');
renderer.write(colorText('~~~ Hello world! ~~~'));
renderer.onDidChangeMaximumDimensions(dim => {
renderer.onDidChangeMaximumDimensions((dim: any) => {
console.log(`Dimensions for renderer changed: columns=${dim.columns}, rows=${dim.rows}`);
});
}));
@ -159,7 +185,7 @@ export function activate(context: vscode.ExtensionContext) {
const shell = (<any>vscode.window).createTerminalRenderer('fake shell');
shell.write('Type and press enter to echo the text\r\n\r\n');
let line = '';
shell.onDidAcceptInput(data => {
shell.onDidAcceptInput((data: any) => {
if (data === '\r') {
shell.write(`\r\necho: "${colorText(line)}"\r\n\n`);
line = '';
@ -171,7 +197,7 @@ export function activate(context: vscode.ExtensionContext) {
shell.terminal.show();
}));
context.subscriptions.push(vscode.commands.registerCommand('terminalTest.maximumDimensions', () => {
renderer.maximumDimensions.then(dimensions => {
renderer.maximumDimensions.then((dimensions: any) => {
vscode.window.showInformationMessage(`TerminalRenderer.maximumDimensions: columns=${dimensions.columns}, rows=${dimensions.rows}`);
});
}));
@ -207,7 +233,7 @@ function colorText(text: string): string {
return output;
}
function selectTerminal(): Thenable<vscode.Terminal> {
function selectTerminal(): Thenable<vscode.Terminal | undefined> {
interface TerminalQuickPickItem extends vscode.QuickPickItem {
terminal: vscode.Terminal;
}
@ -219,7 +245,7 @@ function selectTerminal(): Thenable<vscode.Terminal> {
};
});
return vscode.window.showQuickPick(items).then(item => {
return item.terminal;
return item ? item.terminal : undefined;
});
}

View File

@ -5,6 +5,7 @@
"outDir": "out",
"lib": ["es6"],
"sourceMap": true,
"strict": true,
"rootDir": "src"
},
"exclude": ["node_modules", ".vscode-test"]

View File

@ -1,7 +1,6 @@
import * as vscode from 'vscode';
import * as json from 'jsonc-parser';
import * as path from 'path';
import { isNumber } from 'util';
export class JsonOutlineProvider implements vscode.TreeDataProvider<number> {

View File

@ -10,9 +10,9 @@ import { Command, AbstractCommandDescriptor } from './common';
export class MotionState {
public anchor: Position;
public anchor: Position | null;
public cursorDesiredCharacter: number;
public wordCharacterClass: WordCharacters;
public wordCharacterClass: WordCharacters | null;
constructor() {
this.cursorDesiredCharacter = -1;

View File

@ -217,7 +217,7 @@ class PutOperator extends Operator {
let register = ctrl.getDeleteRegister();
if (!register) {
// No delete register - beep!!
return;
return false;
}
let str = register.content;

View File

@ -46,7 +46,7 @@ export class Words {
return result;
}
public static findNextWord(doc: TextDocument, pos: Position, wordCharacterClass: WordCharacters): IWord {
public static findNextWord(doc: TextDocument, pos: Position, wordCharacterClass: WordCharacters): IWord | null {
let lineContent = doc.lineAt(pos.line).text;
let wordType = WordType.NONE;

View File

@ -6,12 +6,12 @@
"lib": [
"es6"
],
"strict": true,
"sourceMap": true,
"strict": true,
"rootDir": "src"
},
"exclude": [
"node_modules",
".vscode-test"
]
}
}

View File

@ -7,6 +7,7 @@
"es6"
],
"sourceMap": true,
"strict": true,
"rootDir": "src"
},
"include": [

View File

@ -5,6 +5,7 @@
"outDir": "out",
"lib": ["es6"],
"sourceMap": true,
"strict": true,
"rootDir": "src"
},
"exclude": ["node_modules", ".vscode-test"]