Exclude specific directories from being parsed by intellisense - visual-studio-code

I am using php-intellisense extension for my Visual Studio Code.
How do I exclude other folders from being parsed by this extension? As of now it only excludes node_modules and vendor folder.

The extension does not seem to have any specific setting so, unless I'm missing something, the only way to accomplish that is the files.exclude directive. It should definitively work with all languages because it basically makes the file or directory totally disappear from the program.
Beware though of the consequences: you won't even see the folder in the file explorer, nor will it show in searches.

There is an opened issue on the author's github. I've just added a comment to explain how to workaround it.
Please have a look to my comment: https://github.com/felixfbecker/php-language-server/issues/159#issuecomment-514581602
In brief, you can change the way the workspace files are scanned in this file :
C:\Users\USER\ .vscode\extensions\felixfbecker.php-intellisense-xxxx\vendor\felixfbecker\language-server\src\ Indexer.php
public function index(): Promise
{
return coroutine(function () {
// Old code using the rootPath
//$pattern = Path::makeAbsolute('**/*.php', $this->rootPath);
// My new pattern
$pattern = Path::makeAbsolute('**/*.php', 'C:/Users/[USER]/Projects/sources/app/code');
$uris = yield $this->filesFinder->find($pattern);
// ...
});
}
Restart VS Code after saving the changes and it will only index the needed path.

Related

How can I manually edit the list of recently opened files in VS Code?

I rely heavily on the File: Open Recent… command to open frequently used files, but yesterday my local Google Drive folder got moved to a new location and now I can no longer access any of the files in that folder through the Open Recent panel because the paths don't match.
The fix would be as simple as replacing "/Google Drive/" with "/Google Drive/My Drive/" but I have no idea what file contains the list of files that appears in the recently opened panel.
I'm assuming it's somewhere in ~/Library/Application Support/Code but not sure where.
I was wondering the same thing the other day and found this while searching for a solution, so I took some time to investigate it today.
It's been a a few weeks since you posted, so hopefully this will still be of help to you.
Also, I'm using Windows and I'm not familiar with macOS, but I think it should be easy enough adjust the solution.
Location of settings
Those setting are stored in the following file: %APPDATA%\Code\User\globalStorage\state.vscdb.
The file is an sqlite3 database, which is used as a key-value store.
It has a single table named ItemTable and the relevant key is history.recentlyOpenedPathsList.
The value has the following structure:
{
"entries": [
{
"folderUri": "/path/to/folder",
"label": "...",
"remoteAuthority": "..."
}
]
}
To view the current list, you can run the following command:
sqlite3.exe -readonly "%APPDATA%\Code\User\globalStorage\state.vscdb" "SELECT [value] FROM ItemTable WHERE [key] = 'history.recentlyOpenedPathsList'" | jq ".entries[].label"
Modifying the settings
Specifically, I was interested in changing the way it's displayed (the label), so I'll detail how I did that, but it should be just as easy to update the path.
Here's the Python code I used to make those edits:
import json, sqlite3
# open the db, get the value and parse it
db = sqlite3.connect('C:/Users/<username>/AppData/Roaming/Code/User/globalStorage/state.vscdb')
history_raw = db.execute("SELECT [value] FROM ItemTable WHERE [key] = 'history.recentlyOpenedPathsList'").fetchone()[0]
history = json.loads(history_raw)
# make the changes you'd like
# ...
# stringify and update
history_raw = json.dumps(history)
db.execute(f"UPDATE ItemTable SET [value] = '{history_raw}' WHERE key = 'history.recentlyOpenedPathsList'")
db.commit()
db.close()
Code references
For reference (mostly for my future self), here are the relevant source code areas.
The settings are read here.
The File->Open Recent uses those values as-is (see here).
However when using the Get Started page, the Recents area is populated here. In the Get Started, the label is presented in a slightly different way:
vscode snapshot
The folder name is the link, and the parent folder is the the text beside it.
This is done by the splitName method.
Notes
Before messing around with the settings file, it would be wise to back it up.
I'm not sure how vscode handles and caches the settings, so I think it's best to close all vscode instances before making any changes.
I haven't played around with it too much, so not sure how characters that need to be json-encoded or html-encoded will play out.
Keep in mind that there might be some state saved by other extensions, so if anything weird happens, blame it on that.
For reference, I'm using vscode 1.74.2.
Links
SQLite command-line tools
jq - command-line JSON processor

Set .history folder as ignored by intellisense

I need to ignore .history folder from intellisense.
Now it looks like this when I start typing Focus:
As you can see intellisense will offer me every Identical class found in .history folder and this is very very confusing (and find correct one).
I try find something in vscode settings, and on editor site but no success.
.history folder is ignored from git, display in explorer, and tslint:
"files.exclude": {
"**/.history": true ...
},
"files.watcherExclude": {
"**/.history/**": true ...
},
"tslint.exclude": ["**/.history/**"] ...
How to achieve ignore .history from intellisense?
Next part is based on the answer from Matt
An important assumption:
Visual Studio Code itself does not contain automatic import and you need an extension for it.
Solution:
I am using extension Auto Import (steoates.autoimport) which contains the setting autoimport.filesToScan. I changed default value from "**/*.{ts,tsx}" to "{src,e2e,node_modules}/**/*.{ts,tsx}" and now everything work as I expected.
Those suggestions are coming whatever extension you have installed that is providing auto-import functionality. Please check to see if that extension has its own exclude setting that you also need to configure
In your settings.json, you could add this:
"autoimport.filesToScan": "./index.{ts,tsx} ./App.{ts,tsx} ./src/**.*.{ts,tsx}"
Or, if you prefer:
"autoimport.filesToScan": "./{index,App,src/**}.{ts,tsx}"

Is there auto-import functionality for typescript in Visual Studio Code?

Is there any shortcut that will allow me to auto generate my typescript imports? Like hitting ctrl+space next to the type name and having the import declaration placed at the top of the file. If not, what about intellisense for filling out the module reference path so that I wont have to do it manually? I would really love to use vscode but having to do manual imports for typescript is killing me.
There are rumors of making it support tsconfig.json (well, better than rumors). This will allow us to be able to use all files for our references.
Your feature would be to create an auto import of all commonly used 3rd party libs into the typings. Perhaps auto scan the files and create a list of ones to go gather. Wouldn't it be fine to just have a quick way to add several of these using tsd directly from Code (interactively)?
I believe the plugin called "TypeScript Importer" does exactly what You mean: https://marketplace.visualstudio.com/items?itemName=pmneo.tsimporter .
Automatically searches for TypeScript definitions in workspace files and provides all known symbols as completion item to allow code completion.
With it You can truly use Ctrl+Space to choose what exactly You would like to be imported.
You can find and install it from Ctrl+Shift+X menu or just by pasting ext install tsimporter in Quick Open menu opened with Ctrl+P.
I know a solution for Visual Studio (not Visual Studio Code, I'm using the 2015 Community edition, which is free), but it needs some setup and coding -- however, I find the results to be adequate.
Basically, in Visual Studio, when using the Web-Essentials extension, .ts files can be dragged into the active document to automatically generate a relative reference path comment:
/// <reference path="lib/foo.ts" />
With which of course we might as well wipe it, because it's an import statement we need, not a reference comment.
For this reason, I recently wrote the following command snippet for Visual Commander, but it should be easily adaptable to other use casese as well. With Visual Commander, your drag the needed imports into the open document, then run the following macro:
using EnvDTE;
using EnvDTE80;
using System.Text.RegularExpressions;
public class C : VisualCommanderExt.ICommand
{
// Called by Visual Commander extension.
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
{
TextDocument doc = (TextDocument)(DTE.ActiveDocument.Object("TextDocument"));
var p = doc.StartPoint.CreateEditPoint();
string s = p.GetText(doc.EndPoint);
p.ReplaceText(doc.EndPoint, this.ReplaceReferences(s), (int)vsEPReplaceTextOptions.vsEPReplaceTextKeepMarkers);
}
// Converts "reference" syntax to "ES6 import" syntax.
private string ReplaceReferences(string text)
{
string pattern = "\\/\\/\\/ *<reference *path *= *\"([^\"]*)(?:\\.ts)\" *\\/>";
var regex = new Regex(pattern);
var matches = Regex.Matches(text, pattern);
return Regex.Replace(text, pattern, "import {} from \"./$1\";");
}
}
When running this snippet, all reference comments in the active document will be replaced with import statements. The above example is converted to:
import {} from "./lib/foo";
This has just been released in version 1.18.
From the release notes:
Auto Import for JavaScript and TypeScript
Speed up your coding with auto imports for JavaScript and TypeScript. The suggestion list now includes all exported symbols in the current project. Just start typing:
If you choose one of the suggestion from another file or module, VS Code will automatically add an import for it. In this example, VS Code adds an import for Hercules to the top of the file:
Auto imports requires TypeScript 2.6+. You can disable auto imports by setting "typescript.autoImportSuggestions.enabled": false.
The files attributes in the tsconfig.json file allows you to set your reference imports in your whole project. It is supported with Visual Studio Code, but please note that if you're using a specific build chain (such as tsify/browserify) it might not work when compiling your project.

How to resolve Unable to find file.cpp in path(s) in Marmalade?

I'm just trying to begin develop a game in Marmalade (6.3). But when I have made my new sources (.cpp, and .h) and added them to the mkb, and then trying to run my program, then I got an error which says that Unable to find file.cpp in path(s). It's for all of my files except the files (game.h, game.cpp, main.cpp) which were made by Marmalade when I have chosen the new 2D game project. Should I add my .cpp and .h files to anywhere else?
Thanks
It is difficult to give a categorical answer without more info. However my guess is that you've copied and pasted from an example and not understood about the syntax of the files section. Basically:
files
{
(foo)
humbug.cpp
)
The "(foo)" might look very innocent, but it actually says that humbug.cpp is actually in directory foo - relative to the mkb file. It is common practice to actually use "(source)" and put all the source files in a directory of that name - making the source layout a bit neater.
Naturally if you have (source) and don't put the files actually in directory source, they won't be found. My guess is that is what you are seeing.
Just to clarify previous answer, The format of files directive is like this -
files
{
(<Path relative to MKB>,<Alternate Path>)
["Name of the parent Group in VS/XCode project","Name of the subparent group"]
fileName.cpp
fileName.h
}
for example I have two files SoundManager.h and SoundManager.cpp in System folder of Source, while MainMenu.h and MainMenu.cpp in Source/UI. Now the files directive would be -
files
{
(Source/System)
["Source","System"] #This part is not required, it's just to arrange your files in IDE project
SoundManager.h
SoundManager.cpp
(Source/UI)
("Source","UI")
MainMenu.h
ManinMenu.cpp
}

SharpSvn: Why was update of subfolder from Empty Depth Checkout skipped?

I'm having some trouble cherrypicking some folders out of a repo using SharpSvn (from C#). I did this:
client.CheckOut( uri, dir, new SvnCheckOutArgs() { Depth = SvnDepth.Empty } );
foreach( var folder in folders )
{
client.Update( folder );
}
But my second call to Update didn't work. It reports that the action was SvnNotifyAction.Skip and nothing gets written to the working copy.
uri is essentially something like: svn://myserver/myrepo/mysdk and dir is something like C:\Test\mysdk. (I've changed exact names for the purposes of this question, but structurally it's identical.)
Then the 1st folder is C:\Test\mysdk\include (this works)
Then the 2nd folder is C:\Test\mysdk\bin\v100\x86 (this one doesn't update)
Why would the first one work but when I get the 2nd folder (nested subfolders) it doesn't Update? It reports that it is skipped? But I don't know how to figure out why.
It turns out that updating the nested subdirectory doesn't work because the parent directories don't exist yet and so the nested subdirectory update is skipped. To fix this, I needed to add an argument to Update to indicate that it should create the parent directories.
(The equivalent svn command line option would be --parents).
client.Update( folder, new SvnUpdateArgs() { UpdateParents = true } );
I discovered this by trying to do it manually from the svn command line (and encountered the same problem.) svn help co offered this tiny clue: --parents : make intermediate directories I'm assuming that UpdateParents and --parents are equivalent. So far so good.