diff --git a/.vscode/settings.json b/.vscode/settings.json index 527ce47f..953e807b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,9 +1,11 @@ -// Place your settings in this file to overwrite default and user settings. { "files.exclude": { "**/out": false // set this to true to hide the "out" folder with the compiled JS files }, "search.exclude": { "**/out": true - } -} \ No newline at end of file + }, + "editor.formatOnSave": true, + "editor.useTabStops": true, + "editor.tabSize": 4 +} diff --git a/contentprovider-sample/locations-syntax.json b/contentprovider-sample/locations-syntax.json index 61acc859..30a947f7 100644 --- a/contentprovider-sample/locations-syntax.json +++ b/contentprovider-sample/locations-syntax.json @@ -1,18 +1,18 @@ { - "name": "Locations", - "scopeName": "source.locations", - "patterns": [ - { - "name": "comment.line.file", - "match": "file:.*$" - }, - { - "name": "keyword.locations", - "match": " \\d+:" - }, - { - "name": "keyword.control.locations", - "match": " \\d+" - } - ] + "name": "Locations", + "scopeName": "source.locations", + "patterns": [ + { + "name": "comment.line.file", + "match": "file:.*$" + }, + { + "name": "keyword.locations", + "match": " \\d+:" + }, + { + "name": "keyword.control.locations", + "match": " \\d+" + } + ] } diff --git a/contentprovider-sample/package.json b/contentprovider-sample/package.json index 148cb71f..c343d015 100644 --- a/contentprovider-sample/package.json +++ b/contentprovider-sample/package.json @@ -1,70 +1,70 @@ { - "name": "references-plusplus", - "displayName": "References++", - "description": "Show the results of 'Find References' as formatted text in an editor", - "version": "0.0.5", - "publisher": "jrieken", - "repository": { - "type": "git", - "url": "https://github.com/Microsoft/vscode-extension-samples" - }, - "bugs": { - "url": "https://github.com/Microsoft/vscode-extension-samples/issues" - }, - "engines": { - "vscode": "^1.4.0" - }, - "categories": [ - "Other" - ], - "activationEvents": [ - "onCommand:editor.printReferences" - ], - "main": "./out/extension", - "contributes": { - "commands": [ - { - "command": "editor.printReferences", - "title": "Show All References" - } - ], - "menus": { - "editor/context": [ - { - "command": "editor.printReferences", - "when": "editorHasReferenceProvider", - "group": "navigation@1.31" - } - ] - }, - "languages": [ - { - "id": "locations", - "aliases": [ - "Locations" - ], - "extensions": [ - ".locations" - ] - } - ], - "grammars": [ - { - "language": "locations", - "path": "./locations-syntax.json", - "scopeName": "source.locations" - } - ] - }, - "scripts": { - "vscode:prepublish": "node ./node_modules/vscode/bin/compile", - "compile": "node ./node_modules/vscode/bin/compile -watch -p ./", - "postinstall": "node ./node_modules/vscode/bin/install" - }, - "devDependencies": { - "tslint": "^3.8.1", - "typescript": "^1.8.5", - "vscode": "^1.0.0", - "@types/node": "^6.0.40" - } + "name": "references-plusplus", + "displayName": "References++", + "description": "Show the results of 'Find References' as formatted text in an editor", + "version": "0.0.5", + "publisher": "jrieken", + "repository": { + "type": "git", + "url": "https://github.com/Microsoft/vscode-extension-samples" + }, + "bugs": { + "url": "https://github.com/Microsoft/vscode-extension-samples/issues" + }, + "engines": { + "vscode": "^1.4.0" + }, + "categories": [ + "Other" + ], + "activationEvents": [ + "onCommand:editor.printReferences" + ], + "main": "./out/extension", + "contributes": { + "commands": [ + { + "command": "editor.printReferences", + "title": "Show All References" + } + ], + "menus": { + "editor/context": [ + { + "command": "editor.printReferences", + "when": "editorHasReferenceProvider", + "group": "navigation@1.31" + } + ] + }, + "languages": [ + { + "id": "locations", + "aliases": [ + "Locations" + ], + "extensions": [ + ".locations" + ] + } + ], + "grammars": [ + { + "language": "locations", + "path": "./locations-syntax.json", + "scopeName": "source.locations" + } + ] + }, + "scripts": { + "vscode:prepublish": "node ./node_modules/vscode/bin/compile", + "compile": "node ./node_modules/vscode/bin/compile -watch -p ./", + "postinstall": "node ./node_modules/vscode/bin/install" + }, + "devDependencies": { + "tslint": "^3.8.1", + "typescript": "^2.1.4", + "vscode": "^1.0.0", + "@types/node": "^6.0.40" + } } diff --git a/contentprovider-sample/src/extension.ts b/contentprovider-sample/src/extension.ts index e00c16d8..97b0dafd 100644 --- a/contentprovider-sample/src/extension.ts +++ b/contentprovider-sample/src/extension.ts @@ -8,25 +8,25 @@ import ContentProvider, { encodeLocation } from './provider'; export function activate(context: ExtensionContext) { - const provider = new ContentProvider(); + const provider = new ContentProvider(); - // register content provider for scheme `references` - // register document link provider for scheme `references` - const providerRegistrations = Disposable.from( - workspace.registerTextDocumentContentProvider(ContentProvider.scheme, provider), - languages.registerDocumentLinkProvider({ scheme: ContentProvider.scheme }, provider) - ); + // register content provider for scheme `references` + // register document link provider for scheme `references` + const providerRegistrations = Disposable.from( + workspace.registerTextDocumentContentProvider(ContentProvider.scheme, provider), + languages.registerDocumentLinkProvider({ scheme: ContentProvider.scheme }, provider) + ); - // register command that crafts an uri with the `references` scheme, - // 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)); - }); + // register command that crafts an uri with the `references` scheme, + // 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)); + }); - context.subscriptions.push( - provider, - commandRegistration, - providerRegistrations - ); + context.subscriptions.push( + provider, + commandRegistration, + providerRegistrations + ); } diff --git a/contentprovider-sample/src/provider.ts b/contentprovider-sample/src/provider.ts index b8e5c057..b85fb273 100644 --- a/contentprovider-sample/src/provider.ts +++ b/contentprovider-sample/src/provider.ts @@ -8,96 +8,96 @@ import ReferencesDocument from './referencesDocument'; export default class Provider implements vscode.TextDocumentContentProvider, vscode.DocumentLinkProvider { - static scheme = 'references'; + static scheme = 'references'; - private _onDidChange = new vscode.EventEmitter(); - private _documents = new Map(); - private _editorDecoration = vscode.window.createTextEditorDecorationType({ textDecoration: 'underline' }); - private _subscriptions: vscode.Disposable; + private _onDidChange = new vscode.EventEmitter(); + private _documents = new Map(); + private _editorDecoration = vscode.window.createTextEditorDecorationType({ textDecoration: 'underline' }); + private _subscriptions: vscode.Disposable; - constructor() { + constructor() { - // Listen to the following events: - // * closeTextDocument - which means we must clear the corresponding model object - `ReferencesDocument` - this._subscriptions = vscode.workspace.onDidCloseTextDocument(doc => this._documents.delete(doc.uri.toString())); - } + // Listen to the following events: + // * closeTextDocument - which means we must clear the corresponding model object - `ReferencesDocument` + this._subscriptions = vscode.workspace.onDidCloseTextDocument(doc => this._documents.delete(doc.uri.toString())); + } - dispose() { - this._subscriptions.dispose(); - this._documents.clear(); - this._editorDecoration.dispose(); - this._onDidChange.dispose(); - } + dispose() { + this._subscriptions.dispose(); + this._documents.clear(); + this._editorDecoration.dispose(); + this._onDidChange.dispose(); + } - /** - * Expose an event to signal changes of _virtual_ documents - * to the editor - */ - get onDidChange() { - return this._onDidChange.event; - } + /** + * Expose an event to signal changes of _virtual_ documents + * to the editor + */ + get onDidChange() { + return this._onDidChange.event; + } - /** - * Provider method that takes an uri of the `references`-scheme and - * resolves its content by (1) running the reference search command - * and (2) formatting the results - */ - provideTextDocumentContent(uri: vscode.Uri): string | Thenable { + /** + * Provider method that takes an uri of the `references`-scheme and + * resolves its content by (1) running the reference search command + * and (2) formatting the results + */ + provideTextDocumentContent(uri: vscode.Uri): string | Thenable { - // already loaded? - let document = this._documents.get(uri.toString()); - if (document) { - return document.value; - } + // already loaded? + let document = this._documents.get(uri.toString()); + if (document) { + return document.value; + } - // Decode target-uri and target-position from the provided uri and execute the - // `reference provider` command (http://code.visualstudio.com/docs/extensionAPI/vscode-api-commands). - // From the result create a references document which is in charge of loading, - // printing, and formatting references - const [target, pos] = decodeLocation(uri); - return vscode.commands.executeCommand('vscode.executeReferenceProvider', target, pos).then(locations => { + // Decode target-uri and target-position from the provided uri and execute the + // `reference provider` command (http://code.visualstudio.com/docs/extensionAPI/vscode-api-commands). + // From the result create a references document which is in charge of loading, + // printing, and formatting references + const [target, pos] = decodeLocation(uri); + return vscode.commands.executeCommand('vscode.executeReferenceProvider', target, pos).then(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.push(...locations.splice(0, idx)); + // 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.push(...locations.splice(0, idx)); - // create document and return its early state - let document = new ReferencesDocument(uri, locations, this._onDidChange); - this._documents.set(uri.toString(), document); - return document.value; - }); - } + // create document and return its early state + let document = new ReferencesDocument(uri, locations, this._onDidChange); + this._documents.set(uri.toString(), document); + return document.value; + }); + } - private static _compareLocations(a: vscode.Location, b: vscode.Location): number { - if (a.uri.toString() < b.uri.toString()) { - return -1; - } else if (a.uri.toString() > b.uri.toString()) { - return 1; - } else { - return a.range.start.compareTo(b.range.start) - } - } + private static _compareLocations(a: vscode.Location, b: vscode.Location): number { + if (a.uri.toString() < b.uri.toString()) { + return -1; + } else if (a.uri.toString() > b.uri.toString()) { + return 1; + } else { + return a.range.start.compareTo(b.range.start) + } + } - provideDocumentLinks(document: vscode.TextDocument, token: vscode.CancellationToken): vscode.DocumentLink[] { - // 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 - const doc = this._documents.get(document.uri.toString()); - if (doc) { - return doc.links; - } - } + provideDocumentLinks(document: vscode.TextDocument, token: vscode.CancellationToken): vscode.DocumentLink[] { + // 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 + const doc = this._documents.get(document.uri.toString()); + if (doc) { + return doc.links; + } + } } let seq = 0; export function encodeLocation(uri: vscode.Uri, pos: vscode.Position): vscode.Uri { - const query = JSON.stringify([uri.toString(), pos.line, pos.character]); - return vscode.Uri.parse(`${Provider.scheme}:References.locations?${query}#${seq++}`); + const query = JSON.stringify([uri.toString(), pos.line, pos.character]); + return vscode.Uri.parse(`${Provider.scheme}:References.locations?${query}#${seq++}`); } export function decodeLocation(uri: vscode.Uri): [vscode.Uri, vscode.Position] { - let [target, line, character] = <[string, number, number]>JSON.parse(uri.query); - return [vscode.Uri.parse(target), new vscode.Position(line, character)]; -} \ No newline at end of file + let [target, line, character] = <[string, number, number]>JSON.parse(uri.query); + return [vscode.Uri.parse(target), new vscode.Position(line, character)]; +} diff --git a/contentprovider-sample/src/referencesDocument.ts b/contentprovider-sample/src/referencesDocument.ts index 298c1f56..beb4c91f 100644 --- a/contentprovider-sample/src/referencesDocument.ts +++ b/contentprovider-sample/src/referencesDocument.ts @@ -7,139 +7,139 @@ import * as vscode from 'vscode'; export default class ReferencesDocument { - private _uri: vscode.Uri; - private _emitter: vscode.EventEmitter; - private _locations: vscode.Location[]; + private _uri: vscode.Uri; + private _emitter: vscode.EventEmitter; + private _locations: vscode.Location[]; - private _lines: string[]; - private _links: vscode.DocumentLink[]; - private _join: Thenable; + private _lines: string[]; + private _links: vscode.DocumentLink[]; + private _join: Thenable; - constructor(uri: vscode.Uri, locations: vscode.Location[], emitter: vscode.EventEmitter) { - this._uri = uri; - this._locations = locations; + constructor(uri: vscode.Uri, locations: vscode.Location[], emitter: vscode.EventEmitter) { + this._uri = uri; + this._locations = locations; - // The ReferencesDocument has access to the event emitter from - // the containg provider. This allows it to signal changes - this._emitter = emitter; + // The ReferencesDocument has access to the event emitter from + // the containg provider. This allows it to signal changes + this._emitter = emitter; - // Start with printing a header and start resolving - this._lines = [`Found ${this._locations.length} references`]; - this._links = []; - this._join = this._populate(); - } + // Start with printing a header and start resolving + this._lines = [`Found ${this._locations.length} references`]; + this._links = []; + this._join = this._populate(); + } - get value() { - return this._lines.join('\n'); - } + get value() { + return this._lines.join('\n'); + } - get links() { - return this._links; - } + get links() { + return this._links; + } - join(): Thenable { - return this._join; - } + join(): Thenable { + return this._join; + } - private _populate() { + private _populate() { - if (this._locations.length === 0) { - return; - } + if (this._locations.length === 0) { + return; + } - // fetch one by one, update doc asap - return new Promise(resolve => { + // fetch one by one, update doc asap + return new Promise(resolve => { - let index = 0; + let index = 0; - let next = () => { + let next = () => { - // We have seen all groups - if (index >= this._locations.length) { - resolve(this); - return; - } + // We have seen all groups + if (index >= this._locations.length) { + resolve(this); + return; + } - // We know that this._locations is sorted by uri - // such that we can now iterate and collect ranges - // until the uri changes - let loc = this._locations[index]; - let uri = loc.uri; - let ranges = [loc.range]; - while (++index < this._locations.length) { - loc = this._locations[index]; - if (loc.uri.toString() !== uri.toString()) { - break; - } else { - ranges.push(loc.range); - } - } + // We know that this._locations is sorted by uri + // such that we can now iterate and collect ranges + // until the uri changes + let loc = this._locations[index]; + let uri = loc.uri; + let ranges = [loc.range]; + while (++index < this._locations.length) { + loc = this._locations[index]; + if (loc.uri.toString() !== uri.toString()) { + break; + } else { + ranges.push(loc.range); + } + } - // We have all ranges of a resource so that it be - // now loaded and formatted - this._fetchAndFormatLocations(uri, ranges).then(lines => { - this._emitter.fire(this._uri); - next(); - }); - } - next(); - }); - } + // We have all ranges of a resource so that it be + // now loaded and formatted + this._fetchAndFormatLocations(uri, ranges).then(lines => { + this._emitter.fire(this._uri); + next(); + }); + } + next(); + }); + } - private _fetchAndFormatLocations(uri: vscode.Uri, ranges: vscode.Range[]): PromiseLike { + private _fetchAndFormatLocations(uri: vscode.Uri, ranges: vscode.Range[]): PromiseLike { - // Fetch the document denoted by the uri and format the matches - // with leading and trailing content form the document. Make sure - // to not duplicate lines - return vscode.workspace.openTextDocument(uri).then(doc => { + // Fetch the document denoted by the uri and format the matches + // with leading and trailing content form the document. Make sure + // to not duplicate lines + return vscode.workspace.openTextDocument(uri).then(doc => { - this._lines.push('', uri.toString()); + this._lines.push('', uri.toString()); - for (let i = 0; i < ranges.length; i++) { - const {start: {line}} = ranges[i]; - this._appendLeading(doc, line, ranges[i - 1]); - this._appendMatch(doc, line, ranges[i], uri); - this._appendTrailing(doc, line, ranges[i + 1]); - } + for (let i = 0; i < ranges.length; i++) { + const {start: {line}} = ranges[i]; + this._appendLeading(doc, line, ranges[i - 1]); + this._appendMatch(doc, line, ranges[i], uri); + this._appendTrailing(doc, line, ranges[i + 1]); + } - }, err => { - this._lines.push('', `Failed to load '${uri.toString()}'\n\n${String(err)}`, ''); - }); - } + }, err => { + this._lines.push('', `Failed to load '${uri.toString()}'\n\n${String(err)}`, ''); + }); + } - private _appendLeading(doc: vscode.TextDocument, line: number, previous: vscode.Range): void { - let from = Math.max(0, line - 3, previous && previous.end.line || 0); - while (++from < line) { - const text = doc.lineAt(from).text; - this._lines.push(` ${from + 1}` + (text && ` ${text}`)); - } - } + private _appendLeading(doc: vscode.TextDocument, line: number, previous: vscode.Range): void { + let from = Math.max(0, line - 3, previous && previous.end.line || 0); + while (++from < line) { + const text = doc.lineAt(from).text; + this._lines.push(` ${from + 1}` + (text && ` ${text}`)); + } + } - private _appendMatch(doc: vscode.TextDocument, line: number, match: vscode.Range, target: vscode.Uri) { - const text = doc.lineAt(line).text; - const preamble = ` ${line + 1}: `; + private _appendMatch(doc: vscode.TextDocument, line: number, match: vscode.Range, target: vscode.Uri) { + const text = doc.lineAt(line).text; + const preamble = ` ${line + 1}: `; - // Append line, use new length of lines-array as line number - // for a link that point to the reference - const len = this._lines.push(preamble + text); + // Append line, use new length of lines-array as line number + // for a link that point to the reference + const len = this._lines.push(preamble + text); - // Create a document link that will reveal the reference - const linkRange = new vscode.Range(len - 1, preamble.length + match.start.character, len - 1, preamble.length + match.end.character); - const linkTarget = target.with({ fragment: String(1 + match.start.line) }); - this._links.push(new vscode.DocumentLink(linkRange, linkTarget)); - } + // Create a document link that will reveal the reference + const linkRange = new vscode.Range(len - 1, preamble.length + match.start.character, len - 1, preamble.length + match.end.character); + const linkTarget = target.with({ fragment: String(1 + match.start.line) }); + this._links.push(new vscode.DocumentLink(linkRange, linkTarget)); + } - private _appendTrailing(doc: vscode.TextDocument, line: number, next: vscode.Range): void { - let to = Math.min(doc.lineCount, line + 3); - if (next && next.start.line - to <= 2) { - return; // next is too close, _appendLeading does the work - } - while (++line < to) { - const text = doc.lineAt(line).text; - this._lines.push(` ${line + 1}` + (text && ` ${text}`)); - } - if (next) { - this._lines.push(` ...`); - } - } + private _appendTrailing(doc: vscode.TextDocument, line: number, next: vscode.Range): void { + let to = Math.min(doc.lineCount, line + 3); + if (next && next.start.line - to <= 2) { + return; // next is too close, _appendLeading does the work + } + while (++line < to) { + const text = doc.lineAt(line).text; + this._lines.push(` ${line + 1}` + (text && ` ${text}`)); + } + if (next) { + this._lines.push(` ...`); + } + } } diff --git a/contentprovider-sample/tsconfig.json b/contentprovider-sample/tsconfig.json index 724656a5..c79b0fa0 100644 --- a/contentprovider-sample/tsconfig.json +++ b/contentprovider-sample/tsconfig.json @@ -1,15 +1,15 @@ { - "compilerOptions": { - "module": "commonjs", - "target": "es5", - "outDir": "out", - "lib": [ - "es6" - ], - "sourceMap": true, - "rootDir": "src" - }, - "exclude": [ - "node_modules" - ] + "compilerOptions": { + "module": "commonjs", + "target": "es5", + "outDir": "out", + "lib": [ + "es6" + ], + "sourceMap": true, + "rootDir": "src" + }, + "exclude": [ + "node_modules" + ] } diff --git a/decorator-sample/package.json b/decorator-sample/package.json index d442008d..2389cad8 100644 --- a/decorator-sample/package.json +++ b/decorator-sample/package.json @@ -21,7 +21,7 @@ }, "devDependencies": { "vscode": "^1.0.0", - "typescript": "^1.6.2", + "typescript": "^2.1.4", "@types/node": "*" } } diff --git a/decorator-sample/src/extension.ts b/decorator-sample/src/extension.ts index 36ef0643..9e01bb90 100644 --- a/decorator-sample/src/extension.ts +++ b/decorator-sample/src/extension.ts @@ -1,12 +1,12 @@ // The module 'vscode' contains the VS Code extensibility API // Import the module and reference it with the alias vscode in your code below -import * as vscode from 'vscode'; +import * as vscode from 'vscode'; // this method is called when vs code is activated export function activate(context: vscode.ExtensionContext) { - + console.log('decorator sample is activated'); - + // create a decorator type that we use to decorate small numbers var smallNumberDecorationType = vscode.window.createTextEditorDecorationType({ borderWidth: '1px', @@ -22,12 +22,12 @@ export function activate(context: vscode.ExtensionContext) { borderColor: 'lightblue' } }); - + // create a decorator type that we use to decorate large numbers var largeNumberDecorationType = vscode.window.createTextEditorDecorationType({ cursor: 'crosshair', backgroundColor: 'rgba(255,0,0,0.3)' - }); + }); var activeEditor = vscode.window.activeTextEditor; if (activeEditor) { @@ -37,44 +37,44 @@ export function activate(context: vscode.ExtensionContext) { vscode.window.onDidChangeActiveTextEditor(editor => { activeEditor = editor; if (editor) { - triggerUpdateDecorations(); + triggerUpdateDecorations(); } }, null, context.subscriptions); - + vscode.workspace.onDidChangeTextDocument(event => { if (activeEditor && event.document === activeEditor.document) { triggerUpdateDecorations(); } }, null, context.subscriptions); - var timeout = null; + var timeout = null; function triggerUpdateDecorations() { if (timeout) { clearTimeout(timeout); } timeout = setTimeout(updateDecorations, 500); } - + function updateDecorations() { if (!activeEditor) { return; } var regEx = /\d+/g; var text = activeEditor.document.getText(); - var smallNumbers : vscode.DecorationOptions[] = []; - var largeNumbers : vscode.DecorationOptions[] = []; + var smallNumbers: vscode.DecorationOptions[] = []; + var largeNumbers: vscode.DecorationOptions[] = []; var match; while (match = regEx.exec(text)) { var startPos = activeEditor.document.positionAt(match.index); var endPos = activeEditor.document.positionAt(match.index + match[0].length); - var decoration = { range: new vscode.Range(startPos, endPos), hoverMessage: 'Number **' + match[0] + '**'}; + var decoration = { range: new vscode.Range(startPos, endPos), hoverMessage: 'Number **' + match[0] + '**' }; if (match[0].length < 3) { smallNumbers.push(decoration); } else { largeNumbers.push(decoration); } - - + + } activeEditor.setDecorations(smallNumberDecorationType, smallNumbers); activeEditor.setDecorations(largeNumberDecorationType, largeNumbers); diff --git a/languageprovider-sample/client/src/clientMain.ts b/languageprovider-sample/client/src/clientMain.ts index 8253dc0a..f692a2d6 100644 --- a/languageprovider-sample/client/src/clientMain.ts +++ b/languageprovider-sample/client/src/clientMain.ts @@ -15,14 +15,14 @@ export function activate(context: ExtensionContext) { let serverModule = context.asAbsolutePath(path.join('server', 'out', 'serverMain.js')); // The debug options for the server let debugOptions = { execArgv: ["--nolazy", "--debug=6004"] }; - + // If the extension is launched in debug mode then the debug server options are used // Otherwise the run options are used let serverOptions: ServerOptions = { - run : { module: serverModule, transport: TransportKind.ipc }, + run: { module: serverModule, transport: TransportKind.ipc }, debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions } } - + // Options to control the language client let clientOptions: LanguageClientOptions = { // Register the server for plain text documents @@ -34,11 +34,11 @@ export function activate(context: ExtensionContext) { fileEvents: workspace.createFileSystemWatcher('**/.clientrc') } } - + // Create the language client and start the client. let disposable = new LanguageClient('languageServerExample', 'Language Server Example', serverOptions, clientOptions).start(); - + // Push the disposable to the context's subscriptions so that the // client can be deactivated on extension deactivation context.subscriptions.push(disposable); -} \ No newline at end of file +} diff --git a/languageprovider-sample/client/tsconfig.json b/languageprovider-sample/client/tsconfig.json index 0ee43fa2..8f8a3196 100644 --- a/languageprovider-sample/client/tsconfig.json +++ b/languageprovider-sample/client/tsconfig.json @@ -6,7 +6,8 @@ "skipLibCheck": true, "sourceMap": true, "lib": [ - "es5", "es2015.promise" + "es5", + "es2015.promise" ] } -} \ No newline at end of file +} diff --git a/languageprovider-sample/server/package.json b/languageprovider-sample/server/package.json index 6aa6beec..b579c535 100644 --- a/languageprovider-sample/server/package.json +++ b/languageprovider-sample/server/package.json @@ -1,21 +1,21 @@ { - "name": "language-server-example", - "description": "Example implementation of a language server in node.", - "version": "0.0.1", - "author": "Microsoft Corporation", - "license": "MIT", - "engines": { - "node": "*" - }, - "dependencies": { - "vscode-languageserver": "^2.6.2" - }, - "devDependencies": { - "@types/node": "^6.0.52", - "typescript": "^2.1.4" - }, - "scripts": { - "compile": "tsc -p .", - "watch": "tsc --watch -p ." - } -} \ No newline at end of file + "name": "language-server-example", + "description": "Example implementation of a language server in node.", + "version": "0.0.1", + "author": "Microsoft Corporation", + "license": "MIT", + "engines": { + "node": "*" + }, + "dependencies": { + "vscode-languageserver": "^2.6.2" + }, + "devDependencies": { + "@types/node": "^6.0.52", + "typescript": "^2.1.4" + }, + "scripts": { + "compile": "tsc -p .", + "watch": "tsc --watch -p ." + } +} diff --git a/languageprovider-sample/server/src/serverMain.ts b/languageprovider-sample/server/src/serverMain.ts index 643467b0..35040794 100644 --- a/languageprovider-sample/server/src/serverMain.ts +++ b/languageprovider-sample/server/src/serverMain.ts @@ -79,7 +79,7 @@ function validateTextDocument(textDocument: TextDocument): void { diagnostics.push({ severity: DiagnosticSeverity.Warning, range: { - start: { line: i, character: index}, + start: { line: i, character: index }, end: { line: i, character: index + 10 } }, message: `${line.substr(index, 10)} should be spelled TypeScript`, @@ -121,10 +121,10 @@ connection.onCompletion((textDocumentPosition: TextDocumentPositionParams): Comp connection.onCompletionResolve((item: CompletionItem): CompletionItem => { if (item.data === 1) { item.detail = 'TypeScript details', - item.documentation = 'TypeScript documentation' + item.documentation = 'TypeScript documentation' } else if (item.data === 2) { item.detail = 'JavaScript details', - item.documentation = 'JavaScript documentation' + item.documentation = 'JavaScript documentation' } return item; }); @@ -150,4 +150,4 @@ connection.onDidCloseTextDocument((params) => { */ // Listen on the connection -connection.listen(); \ No newline at end of file +connection.listen(); diff --git a/languageprovider-sample/server/tsconfig.json b/languageprovider-sample/server/tsconfig.json index 7b1adf79..8256b1fc 100644 --- a/languageprovider-sample/server/tsconfig.json +++ b/languageprovider-sample/server/tsconfig.json @@ -5,7 +5,8 @@ "outDir": "./out", "sourceMap": true, "lib": [ - "es5", "es2015.promise" + "es5", + "es2015.promise" ] } -} \ No newline at end of file +} diff --git a/previewhtml-sample/package.json b/previewhtml-sample/package.json index f0e709f0..cca4a936 100644 --- a/previewhtml-sample/package.json +++ b/previewhtml-sample/package.json @@ -1,57 +1,57 @@ { - "name": "vscode-css-properties", - "displayName": "Preview CSS Properties Sample", - "description": "A sample illustrating the use of TextContentProviders and the `vscode.previewHtml` command, introduce in 0.10.7", - "version": "0.0.10", - "publisher": "eg2", - "galleryBanner": { - "color": "#5c2d91", - "theme": "dark" - }, - "bugs": { - "url": "https://github.com/Microsoft/vscode-extension-samples/issues", - "email": "egamma@microsoft.com" - }, - "repository": { - "type": "git", - "url": "https://github.com/Microsoft/vscode-extension-samples.git" - }, - "homepage": "https://github.com/Microsoft/vscode-extension-samples/tree/master/textdocumentprovider-sample/README.md", - "categories": [ - "Other" - ], - "engines": { - "vscode": "^0.10.7" - }, - "activationEvents": [ - "onCommand:extension.showCssPropertyPreview" - ], - "main": "./out/src/extension", - "contributes": { - "commands": [ - { - "command": "extension.showCssPropertyPreview", - "title": "Show CSS Properties Preview" - } - ], - "menus": { - "editor/title": [ - { - "command": "extension.showCssPropertyPreview", - "when": "resourceLangId == css" - } - ] - } - }, - "scripts": { - "vscode:prepublish": "node ./node_modules/vscode/bin/compile", - "compile": "node ./node_modules/vscode/bin/compile -watch -p ./", - "postinstall": "node ./node_modules/vscode/bin/install", - "tslint": "tslint -c tslint.json src/extension.ts" - }, - "devDependencies": { - "typescript": "^1.7.5", - "vscode": "^1.0.0", - "@types/node": "*" - } + "name": "vscode-css-properties", + "displayName": "Preview CSS Properties Sample", + "description": "A sample illustrating the use of TextContentProviders and the `vscode.previewHtml` command, introduce in 0.10.7", + "version": "0.0.10", + "publisher": "eg2", + "galleryBanner": { + "color": "#5c2d91", + "theme": "dark" + }, + "bugs": { + "url": "https://github.com/Microsoft/vscode-extension-samples/issues", + "email": "egamma@microsoft.com" + }, + "repository": { + "type": "git", + "url": "https://github.com/Microsoft/vscode-extension-samples.git" + }, + "homepage": "https://github.com/Microsoft/vscode-extension-samples/tree/master/textdocumentprovider-sample/README.md", + "categories": [ + "Other" + ], + "engines": { + "vscode": "^0.10.7" + }, + "activationEvents": [ + "onCommand:extension.showCssPropertyPreview" + ], + "main": "./out/src/extension", + "contributes": { + "commands": [ + { + "command": "extension.showCssPropertyPreview", + "title": "Show CSS Properties Preview" + } + ], + "menus": { + "editor/title": [ + { + "command": "extension.showCssPropertyPreview", + "when": "resourceLangId == css" + } + ] + } + }, + "scripts": { + "vscode:prepublish": "node ./node_modules/vscode/bin/compile", + "compile": "node ./node_modules/vscode/bin/compile -watch -p ./", + "postinstall": "node ./node_modules/vscode/bin/install", + "tslint": "tslint -c tslint.json src/extension.ts" + }, + "devDependencies": { + "typescript": "^2.1.4", + "vscode": "^1.0.0", + "@types/node": "*" + } } diff --git a/previewhtml-sample/src/extension.ts b/previewhtml-sample/src/extension.ts index 65820376..e02e8a56 100644 --- a/previewhtml-sample/src/extension.ts +++ b/previewhtml-sample/src/extension.ts @@ -7,106 +7,103 @@ import * as vscode from 'vscode'; export function activate(context: vscode.ExtensionContext) { - let previewUri = vscode.Uri.parse('css-preview://authority/css-preview'); + let previewUri = vscode.Uri.parse('css-preview://authority/css-preview'); - class TextDocumentContentProvider implements vscode.TextDocumentContentProvider { - private _onDidChange = new vscode.EventEmitter(); + class TextDocumentContentProvider implements vscode.TextDocumentContentProvider { + private _onDidChange = new vscode.EventEmitter(); - public provideTextDocumentContent(uri: vscode.Uri): string { - return this.createCssSnippet(); - } + public provideTextDocumentContent(uri: vscode.Uri): string { + return this.createCssSnippet(); + } - get onDidChange(): vscode.Event { - return this._onDidChange.event; - } + get onDidChange(): vscode.Event { + return this._onDidChange.event; + } - public update(uri: vscode.Uri) { - this._onDidChange.fire(uri); - } + public update(uri: vscode.Uri) { + this._onDidChange.fire(uri); + } - private createCssSnippet() { - let editor = vscode.window.activeTextEditor; - if (!(editor.document.languageId === 'css')) { - return this.errorSnippet("Active editor doesn't show a CSS document - no properties to preview.") - } - return this.extractSnippet(); - } + private createCssSnippet() { + let editor = vscode.window.activeTextEditor; + if (!(editor.document.languageId === 'css')) { + return this.errorSnippet("Active editor doesn't show a CSS document - no properties to preview.") + } + return this.extractSnippet(); + } - private extractSnippet(): string { - let editor = vscode.window.activeTextEditor; - let text = editor.document.getText(); - let selStart = editor.document.offsetAt(editor.selection.anchor); - let propStart = text.lastIndexOf('{', selStart); - let propEnd = text.indexOf('}', selStart); + private extractSnippet(): string { + let editor = vscode.window.activeTextEditor; + let text = editor.document.getText(); + let selStart = editor.document.offsetAt(editor.selection.anchor); + let propStart = text.lastIndexOf('{', selStart); + let propEnd = text.indexOf('}', selStart); - if (propStart === -1 || propEnd === -1) { - return this.errorSnippet("Cannot determine the rule's properties."); - } else { - return this.snippet(editor.document, propStart, propEnd); - } - } + if (propStart === -1 || propEnd === -1) { + return this.errorSnippet("Cannot determine the rule's properties."); + } else { + return this.snippet(editor.document, propStart, propEnd); + } + } - private errorSnippet(error: string): string { - return ` - - ${error} - `; - } + private errorSnippet(error: string): string { + return ` + + ${error} + `; + } - private snippet(document: vscode.TextDocument, propStart: number, propEnd: number): string { - const properties = document.getText().slice(propStart + 1, propEnd); - return ` - -
Preview of the CSS properties -
-
Lorem ipsum dolor sit amet, mi et mauris nec ac luctus lorem, proin leo nulla integer metus vestibulum lobortis, eget
- `; - } - } + private snippet(document: vscode.TextDocument, propStart: number, propEnd: number): string { + const properties = document.getText().slice(propStart + 1, propEnd); + return ` + +
Preview of the CSS properties +
+
Lorem ipsum dolor sit amet, mi et mauris nec ac luctus lorem, proin leo nulla integer metus vestibulum lobortis, eget
+ `; + } + } - let provider = new TextDocumentContentProvider(); - let registration = vscode.workspace.registerTextDocumentContentProvider('css-preview', provider); + let provider = new TextDocumentContentProvider(); + let registration = vscode.workspace.registerTextDocumentContentProvider('css-preview', provider); - vscode.workspace.onDidChangeTextDocument((e: vscode.TextDocumentChangeEvent) => { - if (e.document === vscode.window.activeTextEditor.document) { - provider.update(previewUri); - } - }); + vscode.workspace.onDidChangeTextDocument((e: vscode.TextDocumentChangeEvent) => { + if (e.document === vscode.window.activeTextEditor.document) { + provider.update(previewUri); + } + }); - vscode.window.onDidChangeTextEditorSelection((e: vscode.TextEditorSelectionChangeEvent) => { - if (e.textEditor === vscode.window.activeTextEditor) { - provider.update(previewUri); - } - }) + vscode.window.onDidChangeTextEditorSelection((e: vscode.TextEditorSelectionChangeEvent) => { + if (e.textEditor === vscode.window.activeTextEditor) { + provider.update(previewUri); + } + }) - let disposable = vscode.commands.registerCommand('extension.showCssPropertyPreview', () => { - return vscode.commands.executeCommand('vscode.previewHtml', previewUri, vscode.ViewColumn.Two, 'CSS Property Preview').then((success) => { - }, (reason) => { - vscode.window.showErrorMessage(reason); - }); - }); + let disposable = vscode.commands.registerCommand('extension.showCssPropertyPreview', () => { + return vscode.commands.executeCommand('vscode.previewHtml', previewUri, vscode.ViewColumn.Two, 'CSS Property Preview').then((success) => { + }, (reason) => { + vscode.window.showErrorMessage(reason); + }); + }); - let highlight = vscode.window.createTextEditorDecorationType({ backgroundColor: 'rgba(200,200,200,.35)' }); + let highlight = vscode.window.createTextEditorDecorationType({ backgroundColor: 'rgba(200,200,200,.35)' }); - vscode.commands.registerCommand('extension.revealCssRule', (uri: vscode.Uri, propStart: number, propEnd: number) => { + vscode.commands.registerCommand('extension.revealCssRule', (uri: vscode.Uri, propStart: number, propEnd: number) => { - for (let editor of vscode.window.visibleTextEditors) { - if (editor.document.uri.toString() === uri.toString()) { - let start = editor.document.positionAt(propStart); - let end = editor.document.positionAt(propEnd + 1); + for (let editor of vscode.window.visibleTextEditors) { + if (editor.document.uri.toString() === uri.toString()) { + let start = editor.document.positionAt(propStart); + let end = editor.document.positionAt(propEnd + 1); - editor.setDecorations(highlight, [new vscode.Range(start, end)]); - setTimeout(() => editor.setDecorations(highlight, []), 1500); - } - } - }); + editor.setDecorations(highlight, [new vscode.Range(start, end)]); + setTimeout(() => editor.setDecorations(highlight, []), 1500); + } + } + }); - context.subscriptions.push(disposable, registration); + context.subscriptions.push(disposable, registration); } - -export function deactivate() { -} \ No newline at end of file diff --git a/statusbar-sample/package.json b/statusbar-sample/package.json index 73bbd5c2..a5703075 100644 --- a/statusbar-sample/package.json +++ b/statusbar-sample/package.json @@ -1,45 +1,44 @@ { - "name": "status-ts", - "displayName": "Selected Line Numbers", - "description": "Shows the number of selected lines in the status bar", - "version": "0.0.1", - "publisher": "bpasero", - "repository": { - "type": "git", - "url": "https://github.com/Microsoft/vscode-extension-samples" - }, - "bugs": { - "url": "https://github.com/Microsoft/vscode-extension-samples/issues" - }, - "engines": { - "vscode": "^1.5.0" - }, - "categories": [ - "Other" - ], - "activationEvents": [ - "*" - ], - "contributes": { - "commands": [ - { - "command": "extension.selectedLines", - "title": "Show Selected Lines" - } - ] - }, - "main": "./out/extension", - "scripts": { - "vscode:prepublish": "tsc -p ./", - "compile": "tsc -watch -p ./", - "postinstall": "node ./node_modules/vscode/bin/install", - "test": "node ./node_modules/vscode/bin/test" - }, - "devDependencies": { - "typescript": "^2.0.3", - "vscode": "^1.0.0", - "mocha": "^2.3.3", - "@types/node": "^6.0.40", - "@types/mocha": "^2.2.32" - } + "name": "status-ts", + "displayName": "Selected Line Numbers", + "description": "Shows the number of selected lines in the status bar", + "version": "0.0.1", + "publisher": "bpasero", + "repository": { + "type": "git", + "url": "https://github.com/Microsoft/vscode-extension-samples" + }, + "bugs": { + "url": "https://github.com/Microsoft/vscode-extension-samples/issues" + }, + "engines": { + "vscode": "^1.5.0" + }, + "categories": [ + "Other" + ], + "activationEvents": [ + "*" + ], + "contributes": { + "commands": [ + { + "command": "extension.selectedLines", + "title": "Show Selected Lines" + } + ] + }, + "main": "./out/extension", + "scripts": { + "vscode:prepublish": "tsc -p ./", + "compile": "tsc -watch -p ./", + "postinstall": "node ./node_modules/vscode/bin/install", + "test": "node ./node_modules/vscode/bin/test" + }, + "devDependencies": { + "typescript": "^2.1.4", + "vscode": "^1.0.0", + "mocha": "^2.3.3", + "@types/node": "^6.0.40" + } } diff --git a/statusbar-sample/src/extension.ts b/statusbar-sample/src/extension.ts index abca2ff3..8a2a688f 100644 --- a/statusbar-sample/src/extension.ts +++ b/statusbar-sample/src/extension.ts @@ -7,53 +7,50 @@ import { ExtensionContext, StatusBarAlignment, window, StatusBarItem, Selection, workspace, TextEditor, commands } from 'vscode'; export function activate(context: ExtensionContext) { - const status = window.createStatusBarItem(StatusBarAlignment.Right, 100); - status.command = 'extension.selectedLines'; - context.subscriptions.push(status); + const status = window.createStatusBarItem(StatusBarAlignment.Right, 100); + status.command = 'extension.selectedLines'; + context.subscriptions.push(status); - context.subscriptions.push(window.onDidChangeActiveTextEditor(e => updateStatus(status))); - context.subscriptions.push(window.onDidChangeTextEditorSelection(e => updateStatus(status))); - context.subscriptions.push(window.onDidChangeTextEditorViewColumn(e => updateStatus(status))); - context.subscriptions.push(workspace.onDidOpenTextDocument(e => updateStatus(status))); - context.subscriptions.push(workspace.onDidCloseTextDocument(e => updateStatus(status))); + context.subscriptions.push(window.onDidChangeActiveTextEditor(e => updateStatus(status))); + context.subscriptions.push(window.onDidChangeTextEditorSelection(e => updateStatus(status))); + context.subscriptions.push(window.onDidChangeTextEditorViewColumn(e => updateStatus(status))); + context.subscriptions.push(workspace.onDidOpenTextDocument(e => updateStatus(status))); + context.subscriptions.push(workspace.onDidCloseTextDocument(e => updateStatus(status))); - context.subscriptions.push(commands.registerCommand('extension.selectedLines', () => { - window.showInformationMessage(getSelectedLines()); - })); + context.subscriptions.push(commands.registerCommand('extension.selectedLines', () => { + window.showInformationMessage(getSelectedLines()); + })); - updateStatus(status); + updateStatus(status); } function updateStatus(status: StatusBarItem): void { - let text = getSelectedLines(); - if (text) { - status.text = '$(megaphone) ' + text; - } + let text = getSelectedLines(); + if (text) { + status.text = '$(megaphone) ' + text; + } - if (text) { - status.show(); - } else { - status.hide(); - } + if (text) { + status.show(); + } else { + status.hide(); + } } function getSelectedLines(): string { - const editor = window.activeTextEditor; - let text: string; + const editor = window.activeTextEditor; + let text: string; - if (editor) { - let lines = 0; - editor.selections.forEach(selection => { - lines += (selection.end.line - selection.start.line + 1); - }); + if (editor) { + let lines = 0; + editor.selections.forEach(selection => { + lines += (selection.end.line - selection.start.line + 1); + }); - if (lines > 0) { - text = `${lines} line(s) selected`; - } - } + if (lines > 0) { + text = `${lines} line(s) selected`; + } + } - return text; + return text; } - -export function deactivate() { -} \ No newline at end of file diff --git a/terminal-sample/package.json b/terminal-sample/package.json index 272e0b40..05241c52 100644 --- a/terminal-sample/package.json +++ b/terminal-sample/package.json @@ -66,7 +66,7 @@ "postinstall": "node ./node_modules/vscode/bin/install" }, "devDependencies": { - "typescript": "^1.8.5", + "typescript": "^2.1.4", "vscode": "^1.0.0", "@types/node": "*" } diff --git a/terminal-sample/src/extension.ts b/terminal-sample/src/extension.ts index 8a135896..7e23d528 100644 --- a/terminal-sample/src/extension.ts +++ b/terminal-sample/src/extension.ts @@ -3,72 +3,72 @@ import * as vscode from 'vscode'; export function activate(context: vscode.ExtensionContext) { - let terminalStack: vscode.Terminal[] = []; + let terminalStack: vscode.Terminal[] = []; - context.subscriptions.push(vscode.commands.registerCommand('terminalTest.createTerminal', () => { - terminalStack.push(vscode.window.createTerminal(`Ext Terminal #${terminalStack.length + 1}`)); - })); - context.subscriptions.push(vscode.commands.registerCommand('terminalTest.hide', () => { - if (terminalStack.length === 0) { - vscode.window.showErrorMessage('No active terminals'); - } - getLatestTerminal().hide(); - })); - context.subscriptions.push(vscode.commands.registerCommand('terminalTest.show', () => { - if (terminalStack.length === 0) { - vscode.window.showErrorMessage('No active terminals'); - } - getLatestTerminal().show(); - })); - context.subscriptions.push(vscode.commands.registerCommand('terminalTest.showPreserveFocus', () => { - if (terminalStack.length === 0) { - vscode.window.showErrorMessage('No active terminals'); - } - getLatestTerminal().show(true); - })); - context.subscriptions.push(vscode.commands.registerCommand('terminalTest.sendText', () => { - if (terminalStack.length === 0) { - vscode.window.showErrorMessage('No active terminals'); - } - getLatestTerminal().sendText("echo 'Hello world!'"); - })); - context.subscriptions.push(vscode.commands.registerCommand('terminalTest.sendTextNoNewLine', () => { - if (terminalStack.length === 0) { - vscode.window.showErrorMessage('No active terminals'); - } - getLatestTerminal().sendText("echo 'Hello world!'", false); - })); - context.subscriptions.push(vscode.commands.registerCommand('terminalTest.dispose', () => { - if (terminalStack.length === 0) { - vscode.window.showErrorMessage('No active terminals'); - } - getLatestTerminal().dispose(); - terminalStack.pop(); - })); - context.subscriptions.push(vscode.commands.registerCommand('terminalTest.createAndSend', () => { - terminalStack.push(vscode.window.createTerminal(`Ext Terminal #${terminalStack.length + 1}`)); - getLatestTerminal().sendText("echo 'Sent text immediately after creating'"); - })); + context.subscriptions.push(vscode.commands.registerCommand('terminalTest.createTerminal', () => { + terminalStack.push(vscode.window.createTerminal(`Ext Terminal #${terminalStack.length + 1}`)); + })); + context.subscriptions.push(vscode.commands.registerCommand('terminalTest.hide', () => { + if (terminalStack.length === 0) { + vscode.window.showErrorMessage('No active terminals'); + } + getLatestTerminal().hide(); + })); + context.subscriptions.push(vscode.commands.registerCommand('terminalTest.show', () => { + if (terminalStack.length === 0) { + vscode.window.showErrorMessage('No active terminals'); + } + getLatestTerminal().show(); + })); + context.subscriptions.push(vscode.commands.registerCommand('terminalTest.showPreserveFocus', () => { + if (terminalStack.length === 0) { + vscode.window.showErrorMessage('No active terminals'); + } + getLatestTerminal().show(true); + })); + context.subscriptions.push(vscode.commands.registerCommand('terminalTest.sendText', () => { + if (terminalStack.length === 0) { + vscode.window.showErrorMessage('No active terminals'); + } + getLatestTerminal().sendText("echo 'Hello world!'"); + })); + context.subscriptions.push(vscode.commands.registerCommand('terminalTest.sendTextNoNewLine', () => { + if (terminalStack.length === 0) { + vscode.window.showErrorMessage('No active terminals'); + } + getLatestTerminal().sendText("echo 'Hello world!'", false); + })); + context.subscriptions.push(vscode.commands.registerCommand('terminalTest.dispose', () => { + if (terminalStack.length === 0) { + vscode.window.showErrorMessage('No active terminals'); + } + getLatestTerminal().dispose(); + terminalStack.pop(); + })); + context.subscriptions.push(vscode.commands.registerCommand('terminalTest.createAndSend', () => { + terminalStack.push(vscode.window.createTerminal(`Ext Terminal #${terminalStack.length + 1}`)); + getLatestTerminal().sendText("echo 'Sent text immediately after creating'"); + })); - // Below coming in version v1.6 - context.subscriptions.push(vscode.commands.registerCommand('terminalTest.createZshLoginShell', () => { - terminalStack.push((vscode.window).createTerminal(`Ext Terminal #${terminalStack.length + 1}`, '/bin/zsh', ['-l'])); - })); - context.subscriptions.push(vscode.commands.registerCommand('terminalTest.processId', () => { - (getLatestTerminal()).processId.then((processId) => { - console.log(`Shell process ID: ${processId}`); - }); - })); - if ('onDidCloseTerminal' in vscode.window) { - (vscode.window).onDidCloseTerminal((terminal) => { - console.log('Terminal closed', terminal); - }); - } + // Below coming in version v1.6 + context.subscriptions.push(vscode.commands.registerCommand('terminalTest.createZshLoginShell', () => { + terminalStack.push((vscode.window).createTerminal(`Ext Terminal #${terminalStack.length + 1}`, '/bin/zsh', ['-l'])); + })); + context.subscriptions.push(vscode.commands.registerCommand('terminalTest.processId', () => { + (getLatestTerminal()).processId.then((processId) => { + console.log(`Shell process ID: ${processId}`); + }); + })); + if ('onDidCloseTerminal' in vscode.window) { + (vscode.window).onDidCloseTerminal((terminal) => { + console.log('Terminal closed', terminal); + }); + } - function getLatestTerminal() { - return terminalStack[terminalStack.length - 1]; - } + function getLatestTerminal() { + return terminalStack[terminalStack.length - 1]; + } } export function deactivate() { -} \ No newline at end of file +} diff --git a/terminal-sample/tsconfig.json b/terminal-sample/tsconfig.json index 724656a5..c79b0fa0 100644 --- a/terminal-sample/tsconfig.json +++ b/terminal-sample/tsconfig.json @@ -1,15 +1,15 @@ { - "compilerOptions": { - "module": "commonjs", - "target": "es5", - "outDir": "out", - "lib": [ - "es6" - ], - "sourceMap": true, - "rootDir": "src" - }, - "exclude": [ - "node_modules" - ] + "compilerOptions": { + "module": "commonjs", + "target": "es5", + "outDir": "out", + "lib": [ + "es6" + ], + "sourceMap": true, + "rootDir": "src" + }, + "exclude": [ + "node_modules" + ] } diff --git a/theme-sample/package.json b/theme-sample/package.json index 188650b9..bf008929 100644 --- a/theme-sample/package.json +++ b/theme-sample/package.json @@ -2,7 +2,9 @@ "name": "theme-sample", "version": "0.1.0", "publisher": "vscode", - "engines": { "vscode": "*" }, + "engines": { + "vscode": "*" + }, "contributes": { "themes": [ { @@ -17,4 +19,4 @@ } ] } -} \ No newline at end of file +} diff --git a/tree-explorer-sample/package.json b/tree-explorer-sample/package.json index a24d31de..5674e341 100644 --- a/tree-explorer-sample/package.json +++ b/tree-explorer-sample/package.json @@ -29,7 +29,7 @@ "postinstall": "node ./node_modules/vscode/bin/install" }, "devDependencies": { - "typescript": "^2.0.3", + "typescript": "^2.1.4", "vscode": "^1.0.0", "@types/node": "*" } diff --git a/tree-explorer-sample/src/extension.ts b/tree-explorer-sample/src/extension.ts index 75771f6c..ab7a8eba 100644 --- a/tree-explorer-sample/src/extension.ts +++ b/tree-explorer-sample/src/extension.ts @@ -7,139 +7,139 @@ import * as fs from 'fs'; import * as path from 'path'; export function activate(context: vscode.ExtensionContext) { - const rootPath = vscode.workspace.rootPath; + const rootPath = vscode.workspace.rootPath; - // The `providerId` here must be identical to `contributes.explorer.treeExplorerNodeProviderId` in package.json. - vscode.window.registerTreeExplorerNodeProvider('depTree', new DepNodeProvider(rootPath)); - - // This command will be invoked using exactly the node you provided in `resolveChildren`. - vscode.commands.registerCommand('extension.openPackageOnNpm', (node: DepNode) => { - if (node.kind === 'leaf') { - vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(`https://www.npmjs.com/package/${node.moduleName}`)); - } - }); + // The `providerId` here must be identical to `contributes.explorer.treeExplorerNodeProviderId` in package.json. + vscode.window.registerTreeExplorerNodeProvider('depTree', new DepNodeProvider(rootPath)); + + // This command will be invoked using exactly the node you provided in `resolveChildren`. + vscode.commands.registerCommand('extension.openPackageOnNpm', (node: DepNode) => { + if (node.kind === 'leaf') { + vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(`https://www.npmjs.com/package/${node.moduleName}`)); + } + }); } class DepNodeProvider implements TreeExplorerNodeProvider { - constructor(private workspaceRoot: string) { + constructor(private workspaceRoot: string) { - } - - /** - * As root node is invisible, its label doesn't matter. - */ - getLabel(node: DepNode): string { - return node.kind === 'root' ? '' : node.moduleName; - } - - /** - * Leaf is unexpandable. - */ - getHasChildren(node: DepNode): boolean { - return node.kind !== 'leaf'; - } - - /** - * Invoke `extension.openPackageOnNpm` command when a Leaf node is clicked. - */ - getClickCommand(node: DepNode): string { - return node.kind === 'leaf' ? 'extension.openPackageOnNpm' : null; - } + } - provideRootNode(): DepNode { - return new Root(); - } - - resolveChildren(node: DepNode): Thenable { - if (!this.workspaceRoot) { - vscode.window.showInformationMessage('No dependency in empty workspace'); - return Promise.resolve([]); - } + /** + * As root node is invisible, its label doesn't matter. + */ + getLabel(node: DepNode): string { + return node.kind === 'root' ? '' : node.moduleName; + } - return new Promise((resolve) => { - switch(node.kind) { - case 'root': - const packageJsonPath = path.join(this.workspaceRoot, 'package.json'); - if (this.pathExists(packageJsonPath)) { - resolve(this.getDepsInPackageJson(packageJsonPath)); - } else { - vscode.window.showInformationMessage('Workspace has no package.json'); - resolve([]); - } - break; - /** - * npm3 has flat dependencies, so indirect dependencies are still in `node_modules`. - */ - case 'node': - resolve(this.getDepsInPackageJson(path.join(this.workspaceRoot, 'node_modules', node.moduleName, 'package.json'))); - break; - case 'leaf': - resolve([]); - } - }); - } - - /** - * Given the path to package.json, read all its dependencies and devDependencies. - */ - private getDepsInPackageJson(packageJsonPath: string): DepNode[] { - if (this.pathExists(packageJsonPath)) { - const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')); - - const toDep = (moduleName: string): DepNode => { - if (this.pathExists(path.join(this.workspaceRoot, 'node_modules', moduleName))) { - return new Node(moduleName); - } else { - return new Leaf(moduleName); - } - } + /** + * Leaf is unexpandable. + */ + getHasChildren(node: DepNode): boolean { + return node.kind !== 'leaf'; + } - const deps = packageJson.dependencies - ? Object.keys(packageJson.dependencies).map(toDep) - : []; - const devDeps = packageJson.devDependencies - ? Object.keys(packageJson.devDependencies).map(toDep) - : []; - return deps.concat(devDeps); - } else { - return []; - } - } + /** + * Invoke `extension.openPackageOnNpm` command when a Leaf node is clicked. + */ + getClickCommand(node: DepNode): string { + return node.kind === 'leaf' ? 'extension.openPackageOnNpm' : null; + } - private pathExists(p: string): boolean { - try { - fs.accessSync(p); - } catch (err) { - return false; - } + provideRootNode(): DepNode { + return new Root(); + } - return true; - } + resolveChildren(node: DepNode): Thenable { + if (!this.workspaceRoot) { + vscode.window.showInformationMessage('No dependency in empty workspace'); + return Promise.resolve([]); + } + + return new Promise((resolve) => { + switch (node.kind) { + case 'root': + const packageJsonPath = path.join(this.workspaceRoot, 'package.json'); + if (this.pathExists(packageJsonPath)) { + resolve(this.getDepsInPackageJson(packageJsonPath)); + } else { + vscode.window.showInformationMessage('Workspace has no package.json'); + resolve([]); + } + break; + /** + * npm3 has flat dependencies, so indirect dependencies are still in `node_modules`. + */ + case 'node': + resolve(this.getDepsInPackageJson(path.join(this.workspaceRoot, 'node_modules', node.moduleName, 'package.json'))); + break; + case 'leaf': + resolve([]); + } + }); + } + + /** + * Given the path to package.json, read all its dependencies and devDependencies. + */ + private getDepsInPackageJson(packageJsonPath: string): DepNode[] { + if (this.pathExists(packageJsonPath)) { + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')); + + const toDep = (moduleName: string): DepNode => { + if (this.pathExists(path.join(this.workspaceRoot, 'node_modules', moduleName))) { + return new Node(moduleName); + } else { + return new Leaf(moduleName); + } + } + + const deps = packageJson.dependencies + ? Object.keys(packageJson.dependencies).map(toDep) + : []; + const devDeps = packageJson.devDependencies + ? Object.keys(packageJson.devDependencies).map(toDep) + : []; + return deps.concat(devDeps); + } else { + return []; + } + } + + private pathExists(p: string): boolean { + try { + fs.accessSync(p); + } catch (err) { + return false; + } + + return true; + } } type DepNode = Root // Root node - | Node // A dependency installed to `node_modules` - | Leaf // A dependency not present in `node_modules` - ; + | Node // A dependency installed to `node_modules` + | Leaf // A dependency not present in `node_modules` + ; class Root { - kind: 'root' = 'root'; + kind: 'root' = 'root'; } class Node { - kind: 'node' = 'node'; - - constructor( - public moduleName: string - ) { - } + kind: 'node' = 'node'; + + constructor( + public moduleName: string + ) { + } } class Leaf { - kind: 'leaf' = 'leaf' + kind: 'leaf' = 'leaf' - constructor( - public moduleName: string - ) { - } -} \ No newline at end of file + constructor( + public moduleName: string + ) { + } +} diff --git a/tree-explorer-sample/tsconfig.json b/tree-explorer-sample/tsconfig.json index 11282c9a..d9689931 100644 --- a/tree-explorer-sample/tsconfig.json +++ b/tree-explorer-sample/tsconfig.json @@ -1,16 +1,16 @@ { - "compilerOptions": { - "module": "commonjs", - "target": "es6", - "outDir": "out", - "lib": [ - "es6" - ], - "sourceMap": true, - "rootDir": "." - }, - "exclude": [ - "node_modules", - ".vscode-test" - ] -} \ No newline at end of file + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "outDir": "out", + "lib": [ + "es6" + ], + "sourceMap": true, + "rootDir": "." + }, + "exclude": [ + "node_modules", + ".vscode-test" + ] +} diff --git a/vim-sample/package.json b/vim-sample/package.json index f097cb0a..a5a2cb34 100644 --- a/vim-sample/package.json +++ b/vim-sample/package.json @@ -70,7 +70,7 @@ "postinstall": "node ./node_modules/vscode/bin/install" }, "devDependencies": { - "typescript": "^1.8.5", + "typescript": "^2.1.4", "vscode": "^1.0.0", "@types/node": "*" } diff --git a/vim-sample/src/common.ts b/vim-sample/src/common.ts index b8113bb9..b1fd460f 100644 --- a/vim-sample/src/common.ts +++ b/vim-sample/src/common.ts @@ -5,7 +5,7 @@ 'use strict'; import * as vscode from 'vscode'; -import {MotionState, Motion} from './motions'; +import { MotionState, Motion } from './motions'; export enum Mode { INSERT, @@ -20,10 +20,10 @@ export interface ModifierKeys { } export class DeleteRegister { - public isWholeLine:boolean; - public content:string; + public isWholeLine: boolean; + public content: string; - constructor(isWholeLine:boolean, content:string) { + constructor(isWholeLine: boolean, content: string) { this.isWholeLine = isWholeLine; this.content = content; } @@ -33,11 +33,11 @@ export interface IController { motionState: MotionState; setMode(mode: Mode): void; - setVisual(newVisual:boolean): void; + setVisual(newVisual: boolean): void; findMotion(input: string): Motion; isMotionPrefix(input: string): boolean; - setDeleteRegister(register:DeleteRegister): void; + setDeleteRegister(register: DeleteRegister): void; getDeleteRegister(): DeleteRegister; } @@ -50,4 +50,4 @@ export abstract class AbstractCommandDescriptor { export interface Command { commandId: string, args?: any[] -} \ No newline at end of file +} diff --git a/vim-sample/src/controller.ts b/vim-sample/src/controller.ts index 684a849a..c6949ff5 100644 --- a/vim-sample/src/controller.ts +++ b/vim-sample/src/controller.ts @@ -14,10 +14,10 @@ import { window } from 'vscode'; -import {Words} from './words'; -import {MotionState, Motion} from './motions'; -import {Mode, IController, DeleteRegister, Command, ModifierKeys} from './common'; -import {Mappings} from './mappings'; +import { Words } from './words'; +import { MotionState, Motion } from './motions'; +import { Mode, IController, DeleteRegister, Command, ModifierKeys } from './common'; +import { Mappings } from './mappings'; export interface ITypeResult { hasConsumedInput: boolean; @@ -35,8 +35,8 @@ export class Controller implements IController { public findMotion(input: string): Motion { return Mappings.findMotion(input); } public isMotionPrefix(input: string): boolean { return Mappings.isMotionPrefix(input); } - private _deleteRegister:DeleteRegister; - public setDeleteRegister(register:DeleteRegister): void { this._deleteRegister = register; } + private _deleteRegister: DeleteRegister; + public setDeleteRegister(register: DeleteRegister): void { this._deleteRegister = register; } public getDeleteRegister(): DeleteRegister { return this._deleteRegister; } constructor() { @@ -219,7 +219,7 @@ export class Controller implements IController { private _interpretNormalModeInput(editor: TextEditor, modifierKeys: ModifierKeys): Thenable { if (this._currentInput.startsWith(':')) { - return window.showInputBox({value: 'tabm'}).then((value) => { + return window.showInputBox({ value: 'tabm' }).then((value) => { let result = this._findMapping(value || '', editor, modifierKeys); return Promise.resolve(result); }); @@ -298,7 +298,7 @@ export class Controller implements IController { } } -function setSelectionAndReveal(editor:TextEditor, anchor:Position, line: number, char: number): void { +function setSelectionAndReveal(editor: TextEditor, anchor: Position, line: number, char: number): void { editor.selection = new Selection(anchor, new Position(line, char)); revealPosition(editor, line, char); } @@ -310,4 +310,4 @@ function setPositionAndReveal(editor: TextEditor, line: number, char: number): v function revealPosition(editor: TextEditor, line: number, char: number): void { editor.revealRange(new Range(line, char, line, char), TextEditorRevealType.Default); -} \ No newline at end of file +} diff --git a/vim-sample/src/extension.ts b/vim-sample/src/extension.ts index d10ce2f6..5ac15dc4 100644 --- a/vim-sample/src/extension.ts +++ b/vim-sample/src/extension.ts @@ -6,12 +6,12 @@ import * as vscode from 'vscode'; -import {Words} from './words'; -import {MotionState, Motion, Motions} from './motions'; -import {Operator, Operators} from './operators'; -import {Mode, IController, ModifierKeys} from './common'; -import {Mappings} from './mappings'; -import {Controller} from './controller'; +import { Words } from './words'; +import { MotionState, Motion, Motions } from './motions'; +import { Operator, Operators } from './operators'; +import { Mode, IController, ModifierKeys } from './common'; +import { Mappings } from './mappings'; +import { Controller } from './controller'; export function activate(context: vscode.ExtensionContext) { function registerCommandNice(commandId: string, run: (...args: any[]) => void): void { @@ -22,7 +22,7 @@ export function activate(context: vscode.ExtensionContext) { if (!vscode.window.activeTextEditor) { return; } - vimExt.type(key, {ctrl: true}); + vimExt.type(key, { ctrl: true }); }); } @@ -153,7 +153,7 @@ class VimExt { this._ensureState(); } - public type(text: string, modifierKeys: ModifierKeys = {ctrl: false, shifit: false, alt: false}): void { + public type(text: string, modifierKeys: ModifierKeys = { ctrl: false, shifit: false, alt: false }): void { this._controller.type(vscode.window.activeTextEditor, text, modifierKeys).then((r) => { if (r.hasConsumedInput) { this._ensureState(); diff --git a/vim-sample/src/mappings.ts b/vim-sample/src/mappings.ts index 00bca69e..98867420 100644 --- a/vim-sample/src/mappings.ts +++ b/vim-sample/src/mappings.ts @@ -4,10 +4,10 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; -import {TextEditor} from 'vscode'; -import {Motion, Motions} from './motions'; -import {Operator, Operators} from './operators'; -import {IController, Command, AbstractCommandDescriptor, ModifierKeys} from './common'; +import { TextEditor } from 'vscode'; +import { Motion, Motions } from './motions'; +import { Operator, Operators } from './operators'; +import { IController, Command, AbstractCommandDescriptor, ModifierKeys } from './common'; const CHAR_TO_BINDING: { [char: string]: any; } = {}; function defineBinding(char: string, value: any, modifierKeys: ModifierKeys): void { @@ -27,7 +27,7 @@ function getOperator(char: string, modifierKeys: ModifierKeys = {}): Operator { }; function defineCommand(char: string, commandId: string, modifierKeys: ModifierKeys = {}): void { - defineBinding(char + '__command__', {commandId : commandId}, modifierKeys); + defineBinding(char + '__command__', { commandId: commandId }, modifierKeys); }; function getCommand(char: string, modifierKeys: ModifierKeys = {}): Command { return getBinding(char + '__command__', modifierKeys); @@ -105,11 +105,11 @@ defineMotionCommand('tabm>>', Motions.MoveActiveEditorLast); defineMotionCommand('tabm.', Motions.MoveActiveEditorCenter); // Scroll motions -defineMotionCommand('e', Motions.ScrollDownByLine, {ctrl: true}); -defineMotionCommand('d', Motions.ScrollDownByHalfPage, {ctrl: true}); -defineMotionCommand('f', Motions.ScrollDownByPage, {ctrl: true}); -defineMotionCommand('y', Motions.ScrollUpByLine, {ctrl: true}); -defineMotionCommand('u', Motions.ScrollUpByHalfPage, {ctrl: true}); +defineMotionCommand('e', Motions.ScrollDownByLine, { ctrl: true }); +defineMotionCommand('d', Motions.ScrollDownByHalfPage, { ctrl: true }); +defineMotionCommand('f', Motions.ScrollDownByPage, { ctrl: true }); +defineMotionCommand('y', Motions.ScrollUpByLine, { ctrl: true }); +defineMotionCommand('u', Motions.ScrollUpByHalfPage, { ctrl: true }); defineMotionCommand('b', Motions.ScrollUpByPage, { ctrl: true }); defineMotionCommand('zt', Motions.RevealCurrentLineAtTop); @@ -122,8 +122,8 @@ defineMotionCommand('zo', Motions.UnfoldUnder); export interface IFoundOperator { - runNormal(controller: IController, editor:TextEditor): boolean; - runVisual(controller: IController, editor:TextEditor): boolean; + runNormal(controller: IController, editor: TextEditor): boolean; + runVisual(controller: IController, editor: TextEditor): boolean; } export class Mappings { @@ -145,7 +145,7 @@ export class Mappings { let command = Mappings.findMotionCommandFromNumberAndString(parsed, isVisual, modifierKeys); if (!command) { parsed = _parseNumberAndString(input, false); - command= Mappings.findMotionCommandFromNumberAndString(parsed, isVisual, modifierKeys); + command = Mappings.findMotionCommandFromNumberAndString(parsed, isVisual, modifierKeys); } return command; } @@ -164,7 +164,7 @@ export class Mappings { if (!motionCommand) { motionCommand = getMotionCommand(numberAndString.input, modifierKeys); } - return motionCommand ? motionCommand.createCommand({ isVisual: isVisual, repeat: numberAndString.hasRepeatCount ? numberAndString.repeatCount : undefined}) : null; + return motionCommand ? motionCommand.createCommand({ isVisual: isVisual, repeat: numberAndString.hasRepeatCount ? numberAndString.repeatCount : undefined }) : null; } public static findOperator(input: string, modifierKeys: ModifierKeys): IFoundOperator { diff --git a/vim-sample/src/motions.ts b/vim-sample/src/motions.ts index 07cc1596..d08d4d1d 100644 --- a/vim-sample/src/motions.ts +++ b/vim-sample/src/motions.ts @@ -4,9 +4,9 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; -import {Position, TextDocument, window} from 'vscode'; -import {Words, WordCharacters} from './words'; -import {Command, AbstractCommandDescriptor} from './common'; +import { Position, TextDocument, window } from 'vscode'; +import { Words, WordCharacters } from './words'; +import { Command, AbstractCommandDescriptor } from './common'; export class MotionState { @@ -25,7 +25,7 @@ export class MotionState { export abstract class Motion { public abstract run(doc: TextDocument, pos: Position, state: MotionState): Position; - public repeat(hasRepeatCount:boolean, count: number): Motion { + public repeat(hasRepeatCount: boolean, count: number): Motion { if (!hasRepeatCount) { return this; } @@ -192,7 +192,7 @@ class GoToLineUndefinedMotion extends Motion { return pos; } - public repeat(hasRepeatCount:boolean, count: number): Motion { + public repeat(hasRepeatCount: boolean, count: number): Motion { if (!hasRepeatCount) { return Motions.GoToLastLine; } @@ -202,7 +202,7 @@ class GoToLineUndefinedMotion extends Motion { abstract class GoToLineMotion extends Motion { - protected firstNonWhitespaceChar(doc: TextDocument, line:number): number { + protected firstNonWhitespaceChar(doc: TextDocument, line: number): number { let lineContent = doc.lineAt(line).text; let character = 0; while (character < lineContent.length) { @@ -231,9 +231,9 @@ class GoToLastLineMotion extends GoToLineMotion { } class GoToLineDefinedMotion extends GoToLineMotion { - private _lineNumber:number; + private _lineNumber: number; - constructor(lineNumber:number) { + constructor(lineNumber: number) { super(); this._lineNumber = lineNumber; } diff --git a/vim-sample/src/operators.ts b/vim-sample/src/operators.ts index 716a30ef..d173ff2f 100644 --- a/vim-sample/src/operators.ts +++ b/vim-sample/src/operators.ts @@ -4,33 +4,33 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; -import {Position, Selection, Range, TextDocument, TextEditor, TextEditorRevealType} from 'vscode'; -import {MotionState, Motion, Motions} from './motions'; -import {Mode, IController, DeleteRegister} from './common'; +import { Position, Selection, Range, TextDocument, TextEditor, TextEditorRevealType } from 'vscode'; +import { MotionState, Motion, Motions } from './motions'; +import { Mode, IController, DeleteRegister } from './common'; export abstract class Operator { - public abstract runNormalMode(ctrl: IController, ed:TextEditor, repeatCount: number, args: string): boolean; - public abstract runVisualMode(ctrl: IController, ed:TextEditor, args: string): boolean; + public abstract runNormalMode(ctrl: IController, ed: TextEditor, repeatCount: number, args: string): boolean; + public abstract runVisualMode(ctrl: IController, ed: TextEditor, args: string): boolean; - protected doc(ed:TextEditor): TextDocument { + protected doc(ed: TextEditor): TextDocument { return ed.document; } - protected pos(ed:TextEditor): Position { + protected pos(ed: TextEditor): Position { return ed.selection.active; } - protected sel(ed:TextEditor): Selection { + protected sel(ed: TextEditor): Selection { return ed.selection; } - protected setPosReveal(ed:TextEditor, line: number, char: number): void { + protected setPosReveal(ed: TextEditor, line: number, char: number): void { ed.selection = new Selection(new Position(line, char), new Position(line, char)); ed.revealRange(ed.selection, TextEditorRevealType.Default); } - protected delete(ctrl:IController, ed:TextEditor, isWholeLine:boolean, range:Range): void { + protected delete(ctrl: IController, ed: TextEditor, isWholeLine: boolean, range: Range): void { ctrl.setDeleteRegister(new DeleteRegister(isWholeLine, ed.document.getText(range))); ed.edit((builder) => { builder.delete(range); @@ -39,25 +39,25 @@ export abstract class Operator { } abstract class OperatorWithNoArgs extends Operator { - public runNormalMode(ctrl: IController, ed:TextEditor, repeatCount: number, args: string): boolean { + public runNormalMode(ctrl: IController, ed: TextEditor, repeatCount: number, args: string): boolean { this._run(ctrl, ed); return true; } - public runVisualMode(ctrl: IController, ed:TextEditor, args: string): boolean { + public runVisualMode(ctrl: IController, ed: TextEditor, args: string): boolean { this._run(ctrl, ed); return true; } - protected abstract _run(ctrl: IController, ed:TextEditor): void; + protected abstract _run(ctrl: IController, ed: TextEditor): void; } class InsertOperator extends OperatorWithNoArgs { - protected _run(ctrl: IController, ed:TextEditor): void { + protected _run(ctrl: IController, ed: TextEditor): void { ctrl.setMode(Mode.INSERT); } } class AppendOperator extends OperatorWithNoArgs { - protected _run(ctrl: IController, ed:TextEditor): void { + protected _run(ctrl: IController, ed: TextEditor): void { let newPos = Motions.RightMotion.run(this.doc(ed), this.pos(ed), ctrl.motionState); this.setPosReveal(ed, newPos.line, newPos.character); ctrl.setMode(Mode.INSERT); @@ -65,7 +65,7 @@ class AppendOperator extends OperatorWithNoArgs { } class AppendEndOfLineOperator extends OperatorWithNoArgs { - protected _run(ctrl: IController, ed:TextEditor): void { + protected _run(ctrl: IController, ed: TextEditor): void { let newPos = Motions.EndOfLine.run(this.doc(ed), this.pos(ed), ctrl.motionState); this.setPosReveal(ed, newPos.line, newPos.character); ctrl.setMode(Mode.INSERT); @@ -73,14 +73,14 @@ class AppendEndOfLineOperator extends OperatorWithNoArgs { } class VisualOperator extends OperatorWithNoArgs { - protected _run(ctrl: IController, ed:TextEditor): void { + protected _run(ctrl: IController, ed: TextEditor): void { ctrl.motionState.anchor = this.pos(ed); ctrl.setVisual(true); } } class DeleteCharUnderCursorOperator extends Operator { - public runNormalMode(ctrl: IController, ed:TextEditor, repeatCount: number, args: string): boolean { + public runNormalMode(ctrl: IController, ed: TextEditor, repeatCount: number, args: string): boolean { let to = Motions.NextCharacter.repeat(repeatCount > 1, repeatCount).run(this.doc(ed), this.pos(ed), ctrl.motionState); let from = this.pos(ed); @@ -89,7 +89,7 @@ class DeleteCharUnderCursorOperator extends Operator { return true; } - public runVisualMode(ctrl: IController, ed:TextEditor, args: string): boolean { + public runVisualMode(ctrl: IController, ed: TextEditor, args: string): boolean { let sel = this.sel(ed); this.delete(ctrl, ed, false, sel); return true; @@ -97,7 +97,7 @@ class DeleteCharUnderCursorOperator extends Operator { } class DeleteLineOperator extends Operator { - public runNormalMode(ctrl: IController, ed:TextEditor, repeatCount: number, args: string): boolean { + public runNormalMode(ctrl: IController, ed: TextEditor, repeatCount: number, args: string): boolean { let pos = this.pos(ed); let doc = this.doc(ed); @@ -123,7 +123,7 @@ class DeleteLineOperator extends Operator { return true; } - public runVisualMode(ctrl: IController, ed:TextEditor, args: string): boolean { + public runVisualMode(ctrl: IController, ed: TextEditor, args: string): boolean { let sel = this.sel(ed); this.delete(ctrl, ed, false, sel); return true; @@ -131,7 +131,7 @@ class DeleteLineOperator extends Operator { } abstract class OperatorWithMotion extends Operator { - public runNormalMode(ctrl: IController, ed:TextEditor, repeatCount: number, args: string): boolean { + public runNormalMode(ctrl: IController, ed: TextEditor, repeatCount: number, args: string): boolean { let motion = ctrl.findMotion(args); if (!motion) { @@ -147,12 +147,12 @@ abstract class OperatorWithMotion extends Operator { return this._runNormalMode(ctrl, ed, motion.repeat(repeatCount > 1, repeatCount)); } - protected abstract _runNormalMode(ctrl: IController, ed:TextEditor, motion: Motion): boolean; + protected abstract _runNormalMode(ctrl: IController, ed: TextEditor, motion: Motion): boolean; } class DeleteToOperator extends OperatorWithMotion { - public runNormalMode(ctrl: IController, ed:TextEditor, repeatCount: number, args: string): boolean { + public runNormalMode(ctrl: IController, ed: TextEditor, repeatCount: number, args: string): boolean { if (args === 'd') { // dd return Operators.DeleteLine.runNormalMode(ctrl, ed, repeatCount, args); @@ -160,7 +160,7 @@ class DeleteToOperator extends OperatorWithMotion { return super.runNormalMode(ctrl, ed, repeatCount, args); } - protected _runNormalMode(ctrl: IController, ed:TextEditor, motion: Motion): boolean { + protected _runNormalMode(ctrl: IController, ed: TextEditor, motion: Motion): boolean { let to = motion.run(this.doc(ed), this.pos(ed), ctrl.motionState); let from = this.pos(ed); @@ -169,7 +169,7 @@ class DeleteToOperator extends OperatorWithMotion { return true; } - public runVisualMode(ctrl: IController, ed:TextEditor, args: string): boolean { + public runVisualMode(ctrl: IController, ed: TextEditor, args: string): boolean { let sel = this.sel(ed); this.delete(ctrl, ed, false, sel); return true; @@ -178,7 +178,7 @@ class DeleteToOperator extends OperatorWithMotion { class PutOperator extends Operator { - public runNormalMode(ctrl: IController, ed:TextEditor, repeatCount: number, args: string): boolean { + public runNormalMode(ctrl: IController, ed: TextEditor, repeatCount: number, args: string): boolean { let register = ctrl.getDeleteRegister(); if (!register) { // No delete register - beep!! @@ -199,7 +199,7 @@ class PutOperator extends Operator { let insertLine = pos.line + 1; let insertCharacter = 0; - if (insertLine >= doc.lineCount) { + if (insertLine >= doc.lineCount) { // on last line insertLine = doc.lineCount - 1; insertCharacter = doc.lineAt(insertLine).text.length; @@ -213,7 +213,7 @@ class PutOperator extends Operator { return true; } - public runVisualMode(ctrl: IController, ed:TextEditor, args: string): boolean { + public runVisualMode(ctrl: IController, ed: TextEditor, args: string): boolean { let register = ctrl.getDeleteRegister(); if (!register) { // No delete register - beep!! @@ -233,7 +233,7 @@ class PutOperator extends Operator { class ReplaceOperator extends Operator { - public runNormalMode(ctrl: IController, ed:TextEditor, repeatCount: number, args: string): boolean { + public runNormalMode(ctrl: IController, ed: TextEditor, repeatCount: number, args: string): boolean { if (args.length === 0) { // input not ready return false; @@ -254,7 +254,7 @@ class ReplaceOperator extends Operator { return true; } - public runVisualMode(ctrl: IController, ed:TextEditor, args: string): boolean { + public runVisualMode(ctrl: IController, ed: TextEditor, args: string): boolean { if (args.length === 0) { // input not ready return false; @@ -284,12 +284,12 @@ class ReplaceOperator extends Operator { class ReplaceModeOperator extends Operator { - public runNormalMode(ctrl: IController, ed:TextEditor, repeatCount: number, args: string): boolean { + public runNormalMode(ctrl: IController, ed: TextEditor, repeatCount: number, args: string): boolean { ctrl.setMode(Mode.REPLACE); return true; } - public runVisualMode(ctrl: IController, ed:TextEditor, args: string): boolean { + public runVisualMode(ctrl: IController, ed: TextEditor, args: string): boolean { this.delete(ctrl, ed, false, this.sel(ed)); ctrl.setMode(Mode.INSERT); return true; @@ -299,7 +299,7 @@ class ReplaceModeOperator extends Operator { class ChangeOperator extends OperatorWithMotion { - protected _runNormalMode(ctrl: IController, ed:TextEditor, motion: Motion): boolean { + protected _runNormalMode(ctrl: IController, ed: TextEditor, motion: Motion): boolean { let to = motion.run(this.doc(ed), this.pos(ed), ctrl.motionState); let from = this.pos(ed); @@ -310,7 +310,7 @@ class ChangeOperator extends OperatorWithMotion { return true; } - public runVisualMode(ctrl: IController, ed:TextEditor, args: string): boolean { + public runVisualMode(ctrl: IController, ed: TextEditor, args: string): boolean { let sel = this.sel(ed); this.delete(ctrl, ed, false, sel); @@ -321,7 +321,7 @@ class ChangeOperator extends OperatorWithMotion { } } -function repeatString(str:string, repeatCount:number): string { +function repeatString(str: string, repeatCount: number): string { let result = ''; for (let i = 0; i < repeatCount; i++) { result += str; diff --git a/vim-sample/src/words.ts b/vim-sample/src/words.ts index b992fdf3..10f12daf 100644 --- a/vim-sample/src/words.ts +++ b/vim-sample/src/words.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; -import {Position, TextDocument} from 'vscode'; +import { Position, TextDocument } from 'vscode'; export enum CharacterClass { REGULAR = 0,