Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Allow for completions filter to be case insensitive #2249

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 16 additions & 2 deletions browser/src/Services/Completion/CompletionSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Selectors are functions that take a state and derive a value from it.
*/

import { configuration } from "./../Configuration"
import { ICompletionState } from "./CompletionState"

import * as types from "vscode-languageserver-types"
Expand Down Expand Up @@ -72,11 +73,24 @@ export const filterCompletionOptions = (
return null
}

const filterRegEx = new RegExp("^" + searchText.split("").join(".*") + ".*")
const shouldFilterBeCaseSensitive = configuration.getValue("editor.completions.caseSensitive")

const filterRegEx = shouldFilterBeCaseSensitive
? new RegExp("^" + searchText.split("").join(".*") + ".*")
: new RegExp(
"^" +
searchText
.toLowerCase()
.split("")
.join(".*") +
".*",
)

const filteredOptions = items.filter(f => {
const textToFilterOn = f.filterText || f.label
return textToFilterOn.match(filterRegEx)
return shouldFilterBeCaseSensitive
? textToFilterOn.match(filterRegEx)
: textToFilterOn.toLowerCase().match(filterRegEx)
})

return filteredOptions.sort((itemA, itemB) => {
Expand Down
5 changes: 4 additions & 1 deletion browser/src/Services/Configuration/DefaultConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const BaseConfiguration: IConfigurationValues = {
"editor.quickInfo.delay": 500,

"editor.completions.mode": "oni",
"editor.completions.caseSensitive": true,
"editor.errors.slideOnFocus": true,
"editor.formatting.formatOnSwitchToNormalMode": false,

Expand Down Expand Up @@ -459,7 +460,9 @@ const LinuxConfigOverrides: Partial<IConfigurationValues> = {

const PlatformConfigOverride = Platform.isWindows()
? WindowsConfigOverrides
: Platform.isLinux() ? LinuxConfigOverrides : MacConfigOverrides
: Platform.isLinux()
? LinuxConfigOverrides
: MacConfigOverrides

export const DefaultConfiguration = {
...BaseConfiguration,
Expand Down
3 changes: 3 additions & 0 deletions browser/src/Services/Configuration/IConfigurationValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ export interface IConfigurationValues {
// a custom init.vim, as that may cause problematic behavior
"editor.completions.mode": string

// Decide whether or not the completion matching should be case sensitive
"editor.completions.caseSensitive": boolean
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @bschulte!

It may make sense to make this like the other case sensitive option, ie string | boolean such that it can be smart/true/false.

Then the check becomes something like this:

if (caseSensitivitySetting === false) {
return false
} else if (caseSensitivitySetting === true) {
return true
} else {
// "Smart" casing strategy
// If the string is all lower-case, not case sensitive..
if (searchString === searchString.toLowerCase()) {
return false
// Otherwise, it is case sensitive..
} else {
return true
}
}
}

That should also let you simplify the regex check like we have over here:

const isCaseSensitive = shouldFilterbeCaseSensitive(searchString)
if (!isCaseSensitive) {
searchString = searchString.toLowerCase()
}

That lets us use the same regex for all three cases then.


// If true (default), ligatures are enabled
"editor.fontLigatures": boolean
"editor.fontSize": string
Expand Down