Get Visual Studio Code to look locally when no path is supplied - visual-studio-code

I have a statement like this:
var {ShipmentValidation} = require('ShipmentValidation');
In most projects I work on, I think this means look in my NPM packages for ShipmentValidation. (I usually use './ShipmentValidation' to indicate I need to look locally.)
But I am working on a project now (TestComplete) where I need the "no path" option to look in the local folder for the file. (Because I can't change how TestComplete works.)
Is it possible to configure VS Code to look for "non-path requires" in the local folder (same folder as the current file)?

Looks like I just needed to make a file called jsconfig.json and put this in it:
{
"compilerOptions": {
// This must be specified if "paths" is set
"baseUrl": "."
}
}

Related

opening vscode to latest directory in specified path

Is it possible to have vscode automatically open the newest folder within a specific path?
For example, with this configuration:
{
"folders": [
{
"path": "\\\\FromABC\\Archive",
"name":"From ABC"
},
{
"path": "\\\\FromXYZ\\Archive",
"name":"From XYZ"
}
]
}
I would expect these folders in the workspace to be pointing to \07\07 because those were created today:
\\\\FromABC\\Archive\\2021\\07\\07
\\\\FromXYZ\\Archive\\2021\\07\\07
Is it possible to create a workspace where the folders are opened to the latest folder within each configured path?
There's not enough information in the original question to fully answer it, however, I can suggest a few avenues of attack
Custom Command (error-prone and picky)
Modify Upstream Process (likely the best overall)
Combining Both (perhaps the best for your immediate case)
Creating a Custom Command
Create a new command per https://code.visualstudio.com/api/extension-guides/command#creating-new-commands
VSCode Commands Listing: https://code.visualstudio.com/api/references/commands
new command
detect latest folder through whatever logic you like
call vscode.openFolder to navigate to it
call your custom command through Activation Events (activationEvents) at either onStartupFinished or * (Start Up; less-preferable, but may be required to avoid confusing the editor)
https://code.visualstudio.com/api/references/activation-events#Start-up
Check out Start app when opening project in VS Code? for a few answers related to this
Modifying the Upstream Process
Cutting the gordian knot, it's likely some process (perhaps a human) is creating the directories for you
Change the upstream process so when it creates the directories, it also creates/updates a link to the directory labeled something like latest
/FromABC/Archive/2021/06/03
/FromABC/Archive/2021/07/05
/FromABC/Archive/2021/07/07
/FromABC/Archive/latest --> /FromABC/Archive/2021/07/07
/FromXYZ/Archive/2020/04/12
/FromXYZ/Archive/2021/08/18
/FromXYZ/Archive/latest --> /FromXYZ/Archive/2021/08/18
Then you can always refer to the latest directory and it will always be correct
This is quite common when something can change frequently, but another process is expecting a static path and/or has no way to know the schedule of change
I don't have any Windows systems to try this out with and you may be able to create a regular shortcut for this .. however, you may need a Junction (soft-link) or Hard Link to convince VSCode that the directory is a real directory
https://learn.microsoft.com/en-us/windows/win32/fileio/hard-links-and-junctions
This also provides an opportunity to include more files, such a beta versions of some software, which it's desirable to package into the same directory structure, but not truly the latest stable!
Combining Both
If your upstream process is either not modifiable (or some manual process it's annoying or error-prone to add extras steps to) you can likely combine both solutions to get what you really want
Use the * Action Event to call a script to detect and create the new directory - create a binary or PowerShell script to make your link
In this and with the upstream change, just point VS Code to the latest directory and it shouldn't mind
Not sure on which platform you are, I assume windows, but essentially similar.
Instead of trying to get VSCode to open the latest folder, I would create a script that updates a softlink for each folder to the latest subfolder in it. Then you can point VSCode to the softlink, which can be updated whenever needed to the latest subfolders.

WebdriverIO autocomplete in VSCODE

I am wonder, if it is way how to enable autocompletion for WDIO global variables ( $, $$, browser ) in VSCode. I know, that wdio has support for Webstorm, but it doesn't work for VSCode.
Any idea, how to use autocompletion in VSCode? Without it is pretty hard to create some tests.
I struggled with this as well. Firstly, ensure you've followed the "Autocompletion" Setup described on the website; for example, they require something like the following exist in a file called jsconfig.json at the root of your project:
{
"include": [
"**/*.js",
"**/*.json",
"node_modules/#wdio/sync",
"node_modules/#wdio/mocha-framework"
]
}
You may already have a jsconfig.json; if so, ensure that the node_modules directories are not in a section called "exclude": { ... }. When setting up other things like Babel (for mocha) this may get installed as a default configuration entry. When node_modules is in both include and exclude, exclude takes precedence.
I had zero success importing npm #types pacakges, adding typeAcquisition: {} to jsconfig.json, or adding interface browser; into the file global.d.ts as other people have suggested in various forums.
Auto completion is pre-installed on vs code. If it is not working you might want to check through extension and install. And to use, once the open tag is created, it often auto suggest, just do appropriately then input your attribute.

How to open a specific folder when debugging VS Code extension?

I've developed an extension that reads a directory's package.json file. For the extension to work, you must be inside of a JavaScript file. I'm attempting to test this extension by using a test directory inside of the extension's src directory that houses a package.json file and an index.js file.
My goal is to allow the test to open the directory, open the index.js file and the run the tests there. This way the test directory goes anywhere the extension goes and the tests are predictable based on the package.json file I put into place.
How do I get the tests to open that test directory and run the tests from that specific index.js file?
I figured it out. I had to add the path to the directory into "args" array of the Extension Test object in launch.json.
"args": [
"${workspaceFolder}/src/test/test-directory/",
"${workspaceFolder}/src/test/test-directory/index.js",
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test"
]
I was also able to have index.js open up as well. All of which I realized were totally useless in the tests that I were doing. But at least now I know how to do it and maybe someone else will, too.
Also, if you don't add ${workspaceFolder} in front of the directory you are referencing, VS Code assumes you want a new file created. So instead of opening the index.js file that I had available, it was creating a new empty file named index.js.

VS Code style-lint ignore directories

Is it possible to ignore my CSS path, beacuse I only use stylelint for SCSS validation?
e.g. - I have the following structure:
assets/
css/
scss/
How can I disable the css/ folder from being indexed, trough the settings.json file of VSCode?
I found this in the docs, but I don't know how to implement it in VSCode.
If you're using the VS Code stylelint extension, you can specify ignore paths via the stylelint.configOverrides setting.
Add the following to your VS Code settings.json file:
"stylelint.configOverrides": {
"ignoreFiles": "assets/css/**"
}
Alternatively you can add a .stylelintignore file to the root folder of your project and add the ignore paths there:
assets/css/**
I'm using stylelint#9.2.0 with vscode-stylelint#0.20.4, and for me the .stylelintignore file is not being respected. If i use the CLI it is respected but the vscode plugin does not seem to do this correctly.
Similar to Jack Russell, I found that the VS Code stylelint plugin currently seems to ignore the .stylelintignore file.
To get around this limitation, I removed the .stylelintignore entirely and moved its settings into .stylelintrc instead. I.e. from something like this in .stylelintignore:
ignorethisfolder/**/*
path/to/ignorethisfile.css
To something like this in .stylelintrc:
"ignoreFiles": [
"ignorethisfolder/**/*",
"path/to/ignorethisfile.css",
]

Eclipse: How to Create "Linked Resource" not in .projects Directory?

I am using the Eclipse RCP for Developers to create a version of the Workbench that's specialized to the development we do at work. Most of this has already been done, but I am fine-tuning now.
To initialize a project, users have to create a "preferences" file, which contains various settings. These settings include the "paths" for the code/files they want the project to load. Until now, users have had to nest all relevant code/files in the directory that contains the preferences file, like so:
./folder/file.prefs
./folder/nestedFolder/
./folder/nestedFolder2
(And so on.)
However, I'd like for users to be able to provide relative paths for folders/files not in the home directory, like so:
../../randomFolder/
The only problem I've seen (this works fine for integrating the code/file itself) is getting it to "show up" in the package explorer tool. To do this, you have to create a linked resource (as I already wrote code to do, for nested directories).
However, when I try to link to non-nested folders, I get this error:
ResourceException: Could not created linked resource {path}. Parent resource not accessible.
My code looks like this:
for (String path: FolderPaths) {
IFolder folder = project.getFolder(path)
if (!folder.exists()) {
folder.createLink(pathBase.append(path), IResource.FOLDER, nullProgressMonitor)
}
}
"pathBase" is an "IPath" pointing to the home directory's full-path.
Note that even if the FolderPath "path" is relative to the original prefs file:
../test/folder
Creating an IFolder with the "project.getFolder(path)" method changes it to:
/test/folder
Presumably, this is because the "workspace" is now attempting to create a project folder in the local directory, then link that folder to the path I pass in; this has always worked in the past, but now I get the error above.