-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support clipboard context for value copies
Fixes #423
- Loading branch information
1 parent
ea9d6a4
commit a136ba5
Showing
11 changed files
with
219 additions
and
93 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,3 @@ | ||
console.log('hi');console.log('hi2'); | ||
const env = process.env; | ||
|
||
const mm = require('./micromatch'); | ||
|
||
mm(['foo', 'bar', 'baz', 'qux'], ['f*', 'b*']); | ||
|
||
async function bar() { | ||
return 42; | ||
} | ||
|
||
async function foo() { | ||
const result1 = await bar(); | ||
const result2 = await bar(); | ||
console.log(result1 + result2); | ||
} | ||
|
||
function throwIt() { | ||
setTimeout(() => { | ||
throw new Error('Oh my!'); | ||
}, 0); | ||
} | ||
|
||
let counter = 0; | ||
setInterval(() => { | ||
setTimeout(() => { | ||
//console.log("a\nb\nc\nd" + (++counter)); | ||
}, 0); | ||
}, 2000); | ||
|
||
console.log('Hello world!'); | ||
|
||
var path = './.vscode/launch.json:4:2'; | ||
console.log(path); | ||
var obj = {foo: path}; | ||
console.log(obj); | ||
var arr = [path, obj]; | ||
console.log(arr); | ||
foo(); | ||
console.log(env); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/*--------------------------------------------------------- | ||
* Copyright (C) Microsoft Corporation. All rights reserved. | ||
*--------------------------------------------------------*/ | ||
|
||
import { templateFunctionStr, remoteFunction } from '.'; | ||
|
||
export type CycleReplacer = ( | ||
key: string, | ||
value: unknown, | ||
stack: unknown[], | ||
keys: string[], | ||
) => string; | ||
|
||
/** | ||
* Safe-stringifier. Modified from json-stringify-safe. | ||
* | ||
* @license | ||
* | ||
* The ISC License | ||
* | ||
* Copyright (c) Isaac Z. Schlueter and Contributors | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR | ||
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
export function safeSerializer( | ||
replacer?: (key: string, value: unknown) => unknown, | ||
cycleReplacer: CycleReplacer = (_key, value, stack, keys) => | ||
stack[0] === value | ||
? '[Circular ~]' | ||
: '[Circular ~.' + keys.slice(0, stack.indexOf(value)).join('.') + ']', | ||
) { | ||
const stack: unknown[] = []; | ||
const keys: string[] = []; | ||
|
||
return function (this: unknown, key: string, value: unknown) { | ||
if (stack.length > 0) { | ||
const thisPos = stack.indexOf(this); | ||
if (thisPos === -1) { | ||
stack.push(this); | ||
keys.push(key); | ||
} else { | ||
stack.splice(thisPos + 1); | ||
keys.splice(thisPos, Infinity, key); | ||
} | ||
|
||
if (stack.indexOf(value) !== -1) { | ||
value = cycleReplacer.call(this, key, value, stack, keys); | ||
} | ||
} else { | ||
stack.push(value); | ||
} | ||
|
||
// Modification: avoid JSON.stringify throwing on bigints. | ||
if (typeof value === 'bigint') { | ||
value = value <= Number.MAX_SAFE_INTEGER ? Number(value) : String(value); | ||
} | ||
|
||
return replacer == null ? value : replacer.call(this, key, value); | ||
}; | ||
} | ||
|
||
/** | ||
* Safe-stringifies the value as JSON, replacing | ||
*/ | ||
export const serializeForClipboardTmpl = templateFunctionStr<[string, string]>(` | ||
function (valueToStringify, spaces) { | ||
try { | ||
if (typeof valueToStringify === 'function') { | ||
return '' + valueToStringify; | ||
} | ||
if (typeof Node !== 'undefined' && valueToStringify instanceof Node) { | ||
return valueToStringify.outerHTML; | ||
} | ||
return JSON.stringify(valueToStringify, (${safeSerializer})(), spaces); | ||
} catch (e) { | ||
return '' + valueToStringify; | ||
} | ||
} | ||
`); | ||
|
||
export const serializeForClipboard = remoteFunction<[number], string>(` | ||
function(spaces) { | ||
const result = ${serializeForClipboardTmpl('this', 'spaces')}; | ||
return result; | ||
} | ||
`); |
This file was deleted.
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
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,35 @@ | ||
{ | ||
result : 123 | ||
type : string | ||
variablesReference : <number> | ||
} | ||
{ | ||
result : null | ||
type : string | ||
variablesReference : <number> | ||
} | ||
{ | ||
result : { "foo": "bar", "baz": { "a": [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "b": 123 } } | ||
type : string | ||
variablesReference : <number> | ||
} | ||
{ | ||
result : function hello() { return "world" } | ||
type : string | ||
variablesReference : <number> | ||
} | ||
{ | ||
result : { "foo": true, "recurse": "[Circular ~]" } | ||
type : string | ||
variablesReference : <number> | ||
} | ||
{ | ||
result : "1267650600228229401496703205376" | ||
type : string | ||
variablesReference : <number> | ||
} | ||
{ | ||
result : <div>hi</div> | ||
type : string | ||
variablesReference : <number> | ||
} |
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,24 @@ | ||
{ | ||
text : hello | ||
} | ||
{ | ||
text : 123n | ||
} | ||
{ | ||
text : NaN | ||
} | ||
{ | ||
text : { "foo": "bar", "baz": { "a": [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ], "b": 123 } } | ||
} | ||
{ | ||
text : function hello() { return "world" } | ||
} | ||
{ | ||
text : { "foo": true, "recurse": "[Circular ~]" } | ||
} | ||
{ | ||
text : 1267650600228229401496703205376n | ||
} | ||
{ | ||
text : <div>hi</div> | ||
} |
This file was deleted.
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