When are the "Automatic Optional Chain Completions" triggered in VS Code? - settings

VS Code 1.40 has two new settings javascript.suggest.includeAutomaticOptionalChainCompletions and typescript.suggest.includeAutomaticOptionalChainCompletions and I understand these are supposed to enable or disable the suggestions of optional chain completions by suggesting ?. completions. What I don't understand is when these ?. completions would be triggered. I've set these two settings to true and I'm using TypeScript 3.8, but when I write the following code:
const adventurer = {
name: 'Alice',
cat: {
name: 'Dinah'
}
};
const dogName = adventurer.dog?.
I don't get automatic optional chain completion after dog?..
So what's the use case for the javascript.suggest.includeAutomaticOptionalChainCompletions and typescript.suggest.includeAutomaticOptionalChainCompletions settings in VS Code?

Optional chain completion isn't working in VS Code v1.40. It's working in Insiders v1.41.0 but now you can't turn it off. There's a bug report on this.
Also, optional chain completions are triggered on const dogName = adventurer?. not const dogName = adventurer.dog?.

Related

substrate forkless upgrade tutorial, pallet_scheduler has breaking changes

I am following https://docs.substrate.io/tutorials/v3/forkless-upgrades/ and have added
pallet-scheduler = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.19" } to my Cargo.toml.
It seems that this appears to be a newer version and requires me to specify NoPreimagePostponement and PreimageProvider in pallet_scheduler::Config.
Here is the exact error message:
error[E0046]: not all trait items implemented, missing: PreimageProvider, NoPreimagePostponement
What should I set those value to be? https://docs.rs/pallet-scheduler/latest/pallet_scheduler/trait.Config.html doesn't seem to also have those properties and I'm guessing that the crate hasn't been published yet.
The associated pull request mentions the changes necessary. In short, just set the following to imitate the desired behavior:
type PreimageProvider = ();
type NoPreimagePostponement = ();

How to disable THREE notification messages?

I want to disable console.log's like THREE.WebGLRenderer: Context Lost,
OBJLoader: 1.8330078125ms and so on. Do you have any suggestions?
There is no built-in way to disable these messages, with the exception of OBJLoader2.setLogging.
Messages like these are extremely useful for debugging, not just in your development environment, but also when your code is out in the field.
But if you're hard-set on eliminating these messages, you can redirect logging that uses the console object.
// Place this at the start of your code
const log = console.log;
console.log = () => {};
const warn = console.warn;
console.warn = () => {};
const error = console.error;
console.error = () => {};
With this, anything calling console.log, console.warn, and console.error will be silenced, even es6 modules outside the scope of your main file. This even applies to console message managers like debug.
But YOU can still write to the console by using the redirected functions. For example:
// In your code...
log("test message"); // will print "test message" to the console
This works only because you saved references to the original functions off into the variables like const log.
Download the source, search and replace all console.log, console.warn, and console.error messages. Rebuild the library.
git clone https://github.com/mrdoob/three.js.git
cd three.js
npm install
find src -type f -name '*.js' -exec sed -i '' s/console\\\./\\/\\/console\\./ {} +
find examples/jsm -type f -name '*.js' -exec sed -i '' s/console\\\./\\/\\/console\\./ {} +
find examples/js -type f -name '*.js' -exec sed -i '' s/console\\\./\\/\\/console\\./ {} +
npm run build
note those search and replace lines assume each console line is on a single line by itself.
After searching and replacing (and before building) you can check the results with
git diff
If the results are not correct you can reset all the files to their previous state with
git reset --hard
and then try different expressions or use your favorite text editor's search and replace across files.
People often whine they don't want to change the source but three.js in particular is arguably about changing the source. Three's policy is that you should download a particular version of three.js and write your code to match that specific version. They are then free to break anything and everything with each new version. They make no effort to stay backward compatible between versions so hack your version however you need it to be hacked for your needs.
In the case above, modifying the library is especially trivial given you can practically automate it so if you do take a newer version, after you've fixed all the new incompatibilities you can run these steps again.
The short answer is something like this, which is a spin off of code suggested by mr.doob himself, ironically:
const vrgc = {};
vrgc.console = {
log: console.log,
info: console.info,
warn: console.warn,
error: console.error,
};
Object.keys(vrgc.console)
.forEach(
key => {
console.warn(`hiding console.${key} calls from THREE`)
console[key] = function() {
if ( (typeof arguments[ 0 ] === 'string') && (arguments[ 0 ].substr( 0, 5 ) === 'THREE') ) {
return
// ignore THREE
}
else {
const originalFunc = vrgc.console[key];
originalFunc.apply( console, arguments );
}
}
}
);
Unfortunately, this request has a loooong history of 6+ years... see here, here, here, here, et al...
Adds a logging parameter to the WebGL renderer.
Useful for situations where you don't want logging at all such as production or in a testing environment. Retains true as default but would think false would be a better option? https://github.com/mrdoob/three.js/pull/5835

How to link against frameworks that are not in the standard location?

I tried to link against a private framework in /System/Library/PrivateFrameworks using
#[link(name = "MultitouchSupport", kind = "framework")]
But the linker tells me that the MultitouchSupport framework was not found. I also tried
#[link(name = "/System/Library/PrivateFrameworks/MultitouchSupport", kind = "framework")]
and
#[link(name = "/System/Library/PrivateFrameworks/MultitouchSupport.framework", kind = "framework")]
with the file extension, but neither work.
Is it even possible to link against frameworks that are not in the standard location of /System/Library/Frameworks?
I found out that WiSaGaN's suggestion was quite close to the solution: It works if you use search=framework in the build.rs.
The solution was to use the following build.rs:
fn main()
{
println!("cargo:rustc-link-search=framework={}", "/System/Library/PrivateFrameworks");
}
Thank you, WiSaGaN!
Using this build.rs you can link as usual:
#[link(name = "MultitouchSupport", kind = "framework")]

Using native Windows FileChooser dialog under PyGTK?

I'm using PyGTK's GtkFileChooserButton, which is working - but looks very weird on Windows environment. Is it possible to use native Windows file chooser dialog?
UPDATE
See the comments for possible directions. However, if you decide (like me...) that it doesn't worth the effort, this will make the Gtk FileChooser more tolerable:
def get_win_my_documents():
# based on http://stackoverflow.com/questions/3858851/python-get-windows-special-folders-for-currently-logged-in-user
# and http://stackoverflow.com/questions/6227590/finding-the-users-my-documents-path
CSIDL_PERSONAL = 5 # My Documents
# the 2 stackoverflow answers use different values for this constant!
SHGFP_TYPE_CURRENT = 0 # Get current, not default value
buf = ctypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH)
ctypes.windll.shell32.SHGetFolderPathW(None, CSIDL_PERSONAL, None, SHGFP_TYPE_CURRENT, buf)
if os.path.isdir(buf.value):
return buf.value
else:
# fall back to simple "home" notion
return(os.path.expanduser("~"))
...
my_documents = get_win_my_documents()
chooser.set_current_folder(my_documents)
chooser.add_shortcut_folder(my_documents)
# I'm not sure if it's a general solution, but works for me...
downloads = os.path.join(os.path.expanduser("~"), "Downloads")
if os.path.isdir(downloads):
chooser.add_shortcut_folder(downloads)

Invoke source control compare operation in vs2012 extension

I am writing a vs2012 extension that will talk to TFS 2010 (though I would prefer if it could also work with tfs2012).
I need to invoke a compare operations on a file from the extension.
I want to use the default compare tool that is configured in visual studio at the moment of the innovation (because the user can configure a different compare tool).
I have the location of the file and I want to be able to invoke the following:
open the default compare.
open a compare with latest version
open a compare with workspace version
Use IVsDifferenceService to invoke Visual Studio diff tool from your VSPackage:
private void Compare(string leftFile, string rightFile)
{
var diffService = (IVsDifferenceService)GetService(typeof(SVsDifferenceService));
if (diffService != null)
{
ErrorHandler.ThrowOnFailure(
diffService.OpenComparisonWindow(leftFile, rightFile).Show()
);
}
}
To test it you need to set the workspace and download the file you want to compare:
// TODO: add some error handling
var tpc = new TfsTeamProjectCollection(new Uri("http://tfs.company.com:8080/tfs"));
var vcs = tpc.GetService<VersionControlServer>();
var workspace = vcs.GetWorkspace(Environment.MachineName, vcs.AuthorizedUser);
string localItem = #"C:\workspace\project\somefile.cs";
var folder = workspace.GetWorkingFolderForLocalItem(localItem);
var item = vcs.GetItem(folder.ServerItem, VersionSpec.Latest);
var latestItem = string.Format("{0}~{1}", localItem, item.ChangesetId);
item.DownloadFile(latestItem);
Compare(localItem, latestItem);
References:
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

Resources