Why does scintilla auto-complete leave start of word - autocomplete

I am coding a Notepad++ plug-in to create an IDE for a scripting language that I and some others use.
My problem is that I can't figure out why Scintilla's AutoComplete functionality leaves the start of the string after an AutoComplete selection has been made.
I've tried deleting the start of the string, but this doesn't seem to work either. I suppose I could manually replace the target with the AutoCompletion selection when I get the AutoComplete selection notification, but shouldn't Scintilla do this automagically?

If you set Scintilla.AutoComplete.AutomaticLengthEntered = true, Scintilla will attempt to guess the length of the word and replace it when the AutoComplete entry has been accepted.
If you're showing a custom AutoComplete list using Scintilla.AutoComplete.ShowUserList, the first parameter (listType) is the number of characters that will be replaced when a match is accepted. Similarly, the lengthEntered in Scintilla.AutoComplete.Show is the number of characters to be replaced.

Related

VSCode built-in snippets fail to to show when consecutive letters are typed

If I type one letter of the trigger/prefix, the snippet suggestion works to show the built-in snippets from extensions. But, once I type the next letter in the trigger/prefix...the built-in snippet from the extension is gone. Meaning, it is no longer found anywhere in the dropdown list (you won't find it by scrolling). .
Here is a snapshot confirming that the trigger/prefix is removed from the list
I found that with some built-in snippets from extensions, if I type out the entire word, it will reappear. For example, if I want: 'trycatch', it will be populated in the list when I type 't', disappear when I have typed 'tr', but then reappear when the entire trigger/prefix is typed.
How can i get a built-in snippet from an extension to show in snippet search when 2 or more letters of the trigger/prefix are typed? I am using version 1.75.0
I tried looking at the docs of VSCode, but it's too simple to help. I tried looking at my settings (keyword: snippets) and play around with any possibilities, but nothing seemed to fix it. Any google search comes up empty as well.

Disabling vscode intellisense for only one word or phrase?

Is there a way to create a "blacklist" of words or phrases that get ignored by vscode intellisense?
Right now I get an autocomplete suggestion every time I type error, which results in a small code block that I do not want, as I only want the word error itself.
I'm not looking to disable intellisense entirely, only on this one instance of a particular phrase, and was wondering if it's possible to do that.

Partial autocomplete of the suggestions given by vscode?

Is it possible for the autocomplete feature of vscode to accept only part of the suggestions on Tab?
Basically, we can specify the word separators characters in settings but the autocomplete feature seems to ignore these and replace the complete full word either way.
What I want, for example, is that by specifying the word separator "_" the autocomplete won't replace the full suggestion but only until this character which should effectively be considered the end of the word.
For example, having semi_completions_foo() declared and having written only the initial "se".
"se" + Tab -> "semi_"
"semi_" + Tab -> "semi_completions_"
On the other hand by pressing Enter the full suggestion would be accepted.
"se" + Enter -> "semi_completions_foo"
Is this already implemented?
This is currently not supported by default as of VS Code 1.35 but is tracked by this feature request.
However VS Code does support tabbing through suggestion alternatives after you accept a completion with tab. Just press tab again to switch to the next suggestion from the list.

Multiline regular expression search in Visual Studio Code

Multiline regular expression search doesn't work in VS Code version 1.27.2 .
Theoretically aaa(\n|.)*bbb should find string starting from aaa and ending bbb but it doesn't work.
The solution mentioned here Multi-line regular expressions in Visual Studio Code doesn't work as well.
Multiline search is added in v1.29 released in November 2018. See multi-line search.
VS Code now supports multiline search! Same as in the editor, a regex
search executes in multiline mode only if it contains a \n literal.
The Search view shows a hint next to each multiline match, with the
number of additional match lines.
This feature is possible thanks to the work done in the ripgrep tool
to implement multiline search.
Multiline search is coming to the Find Widget with v1.38. See multiline find "pre-release" notes.
Multi Line search in Find Widget
The Find Widget now supports multiple line text search and replace. By
pressing Ctrl+Enter, you can insert new lines into the input box.
.
Odd that it is Ctrl+Enter in the Find Widget but Shift+Enter in the Search Panel (see Deepu's answer below). Shift+Enter has other functionality when the Find Widget is focused.
yes, you could use regex for mutliple line search in VScode.
To find a multi-line text block starting from aaa and ending with the first bbb (lazy qualifier)
aaa(.|\n)+?bbb
To find a multi-line text block starting from aaa and ending with the last bbb. (greedy qualifier)
aaa(.|\n)+bbb
I have been looking for a quick way to do this, and I have come to the following:
start_text.*?(.|[\n])*?end_text
with start_text and end_text being the bounds of your multiline search.
breaking down the regex ".?(.|[\n])?":
".?" will match any characters from your start text to the end of the line. The "?" is there to ensure that if your end_text is on the same line the . wont just keep going to the end of the line regardless (greedy vs lazy matching)
"(.|[\n])" means either a character\whitespace or a new line
"*?" specifies to match 0 or more of the expression in the parentheses without being greedy.
Examples:
<meta.*?(.|[\n])*?/> will match from the beginning of all meta tags to the end of the respective tags
<script.*?(.|[\n])*?</script> will match from the beginning of all script tags to the respective closing tags
Warning:
Using .*?(.|[\n])*? with improperly or partially filled in start_text or end_text might crash VS Code. I suggest either writing the whole expression out (which doesn't cause a problem) or writing the start and end text before pasting in the regex. In any case, when I tried to delete parts of the starting and ending text VS Code froze and forced me to reload the file. That being said, I honestly could not find something that worked better in VS Code.
Without using regex.
Multi-line search is now possible in vs code version 1.30 and above without using regex.
Type Shift+Enter in the search box to insert a newline, and the search box will grow to show your full multiline query. You can also copy and paste a multiline selection from the editor into the search box.
You can find and replace in multiple lines by using this simple regex : StringStart\r\nStringEnd
For example
public string MethodA(int x)
{
var user;
}
public string MethodB(string y)
{
var user;
}
public string MethodC(int x)
{
var user;
}
public string MethodD(float x)
{
var user;
}
If you want to replace the name of user variable with customer along with method parameter name to user but only for the int ones.
Then the regex to find will be : int x)\r\nEnterBlankSpacesHereToReachTheString{\r\nEnterBlankSpacesHereToReachTheStringvar user
and regex to replace will be : int user)\r\nEnterBlankSpacesHereToReachTheString{\r\nEnterBlankSpacesHereToReachTheStringvar customer
See for reference
I had a similar issue, this works better for me:
aaa[.\n\r\t\S\s]*bbb
This includes carriage return (\r), new line (\n), tab (\t), any whitespece (\s) and any non whitespace (\S). There seems to be some redundancy putting "." and "\S" together, but it doesn't work without both in my case.
No regex way: you can copy multiline text and paste it in "Find in files" form:
result of "Replace all":
(.|\n)+? or [\s\S\r]* or [.\n\r\t\S\s]* may be understandable when viewed in isolation, but in an already complex regex expression, they can add that extra layer of complexity that makes the whole thing unmanageable.
On Windows, for files on the local disk, I find the best solution is to switch to using Notepad++. Not only does it handle multi-line out of the box, it also has a pleasant interface for multi-file search and replace, handles macros gracefully, and is quite light-weight. You can switch back to VScode as soon you have finished your regex changes. Personally, I deleted Notepad++ when I found VScode, but reinstalled it later when I found some of what Notepad++ had to offer was missing in VScode. Both are free to use! I'm sure there's an equivalent on the Mac.
If you are willing to search JavaScript, TypeScript or JSON files I can recommend my VScode extension
It allows for formatting agnostic text search and structural code search
You can find it on codeque.co or at VSCode Marketplace
Your query could look like this
aaa$$mbbb
where $$m means optional multiline set of any characters
Make sure to use text mode for this query
CodeQue can make much more than that!
The reason on this behavior is very simple.
Multiple line search isn't implemented yet.
see: Support multi-line search for Global search

VS Code Refactoring: Change all occurences - but only in block scope

When using "change all occurences" in VS Code, it will just search the whole file for matches and change them. Is there a similar feature doing the same thing, but limiting it to function or block scope?
Let's take an example where I would need that: I'm having a React file with several components and want to refactor a class component to a functional component, so I'm changing all occurences of this.props to props. However, I obviously don't want to change all the other class components as well that are supposed to stay class components. :-)
This seems like such a standard use case, but I'm not able to find it anywhere in VS Code. If it's not possible (yet, or for some good reasons) is there another way to achieve what I'm trying to do?
Check out the 'Add Selection To Next Find Match' functionality. It allows you to highlight the first occurrence you'd like to change, then using a keyboard shortcut, highlight the next occurrence and so on until you've selected all the instances you want to change. When all to-be-changed occurrences are selected, you can edit the selected text normally. Just remember to hit the escape key a couple times after editing to return to a single cursor!
Here are the keybindings for the command, it's Cmd+d on Mac:
https://code.visualstudio.com/docs/getstarted/keybindings
I find it very useful when renaming variables, there's also a shortcut to skip occurrences (Cmd+k Cmd+d) in case there is text you don't want to change in between.