-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added mappings from vscode commands to internal commands
Signed-off-by: Josh Pinkney <joshpinkney@gmail.com>
- Loading branch information
Showing
11 changed files
with
528 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// tslint:disable | ||
// copied from https://github.com/microsoft/vscode/blob/1.37.0/src/vs/base/common/objects.ts | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { isUndefinedOrNull, isArray, isObject } from './types'; | ||
|
||
const _hasOwnProperty = Object.prototype.hasOwnProperty; | ||
|
||
export function cloneAndChange(obj: any, changer: (orig: any) => any): any { | ||
return _cloneAndChange(obj, changer, new Set()); | ||
} | ||
|
||
function _cloneAndChange(obj: any, changer: (orig: any) => any, seen: Set<any>): any { | ||
if (isUndefinedOrNull(obj)) { | ||
return obj; | ||
} | ||
|
||
const changed = changer(obj); | ||
if (typeof changed !== 'undefined') { | ||
return changed; | ||
} | ||
|
||
if (isArray(obj)) { | ||
const r1: any[] = []; | ||
for (const e of obj) { | ||
r1.push(_cloneAndChange(e, changer, seen)); | ||
} | ||
return r1; | ||
} | ||
|
||
if (isObject(obj)) { | ||
if (seen.has(obj)) { | ||
throw new Error('Cannot clone recursive data-structure'); | ||
} | ||
seen.add(obj); | ||
const r2 = {}; | ||
for (let i2 in obj) { | ||
if (_hasOwnProperty.call(obj, i2)) { | ||
(r2 as any)[i2] = _cloneAndChange(obj[i2], changer, seen); | ||
} | ||
} | ||
seen.delete(obj); | ||
return r2; | ||
} | ||
|
||
return obj; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2019 Red Hat, Inc. and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import * as assert from 'assert'; | ||
import { KnownCommands } from '../common/known-commands'; | ||
import URI from 'vscode-uri'; | ||
import { Position } from './types-impl'; | ||
import { fromPosition } from './type-converters'; | ||
|
||
describe('Known Command Conversions', () => { | ||
|
||
it('Should convert position correctly', () => { | ||
|
||
// given | ||
const commandID = 'editor.action.rename'; | ||
const uri = URI.parse('file://my_theia_location'); | ||
const line = 61; | ||
const character = 22; | ||
const position = new Position(line, character); // vscode type position | ||
|
||
assert.ok(KnownCommands.mapped(commandID)); | ||
|
||
// when | ||
// tslint:disable-next-line:no-any | ||
KnownCommands.map(commandID, [uri, position], (mappedID: string, mappedArgs: any[]) => { | ||
|
||
// then | ||
assert.strictEqual(commandID, mappedID); | ||
assert.strictEqual(mappedArgs.length, 2); | ||
assert.deepStrictEqual(uri, mappedArgs[0]); | ||
|
||
const expectedMonacoPosition = fromPosition(position); | ||
assert.deepStrictEqual(expectedMonacoPosition, mappedArgs[1]); | ||
}); | ||
|
||
}); | ||
|
||
it('Does not convert non-monaco action commands', () => { | ||
|
||
// given | ||
const commandID = 'workbench.view.search'; | ||
const line = 61; | ||
const character = 22; | ||
const position = new Position(line, character); // vscode type position | ||
|
||
assert.ok(KnownCommands.mapped(commandID)); | ||
|
||
// when | ||
// tslint:disable-next-line:no-any | ||
KnownCommands.map(commandID, [position], (mappedID: string, mappedArgs: any[]) => { | ||
// then | ||
assert.strictEqual(mappedID, 'search-in-workspace.open'); | ||
assert.strictEqual(mappedArgs.length, 1); | ||
assert.deepStrictEqual(mappedArgs[0], position); | ||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters