@@ -6,10 +6,12 @@ import { unsafeKeys } from "../../../util/object";
6
6
7
7
type IndividualDelimiterText = string | string [ ] ;
8
8
9
- const delimiterToText : Record <
9
+ type DelimiterMap = Record <
10
10
SimpleSurroundingPairName ,
11
11
[ IndividualDelimiterText , IndividualDelimiterText ]
12
- > = Object . freeze ( {
12
+ > ;
13
+
14
+ const delimiterToText : DelimiterMap = Object . freeze ( {
13
15
angleBrackets : [
14
16
[ "</" , "<" ] ,
15
17
[ ">" , "/>" ] ,
@@ -26,20 +28,22 @@ const delimiterToText: Record<
26
28
squareBrackets : [ "[" , "]" ] ,
27
29
} ) ;
28
30
29
- const delimiterToTextNix : Record <
30
- SimpleSurroundingPairName ,
31
- [ IndividualDelimiterText , IndividualDelimiterText ]
32
- > = {
33
- ...delimiterToText ,
34
- singleQuotes : [ "''" , "''" ] ,
35
- } ;
31
+ // FIXME: Probably remove these as part of
32
+ // https://github.com/cursorless-dev/cursorless/issues/1812#issuecomment-1691493746
33
+ const delimiterToTextOverrides : Record < string , Partial < DelimiterMap > > = {
34
+ nix : {
35
+ singleQuotes : [ "''" , "''" ] ,
36
+ } ,
36
37
37
- const delimiterToTextLua : Record <
38
- SimpleSurroundingPairName ,
39
- [ IndividualDelimiterText , IndividualDelimiterText ]
40
- > = {
41
- ...delimiterToText ,
42
- // FIXME: Add [[ ]] somewhere
38
+ lua : {
39
+ // FIXME: Add special double square brackets
40
+ // see https://github.com/cursorless-dev/cursorless/pull/2012#issuecomment-1808214409
41
+ // see also https://github.com/cursorless-dev/cursorless/issues/1812#issuecomment-1691493746
42
+ doubleQuotes : [
43
+ [ '"' , "[[" ] ,
44
+ [ '"' , "]]" ] ,
45
+ ] ,
46
+ } ,
43
47
} ;
44
48
45
49
export const leftToRightMap : Record < string , string > = Object . fromEntries (
@@ -65,22 +69,30 @@ export const complexDelimiterMap: Record<
65
69
} ;
66
70
67
71
/**
68
- * Given a language id, returns a list of all possible delimiters
69
- * for that language.
70
- * @param languageId The language id
72
+ * Given a language id, returns a list of all possible delimiters for that
73
+ * language.
74
+ *
75
+ * Allows us to support languages where the parse tree gives type names to nodes
76
+ * that don't correspond to the actual delimiter.
77
+ *
78
+ * Note that we pass in `undefined` if we are in a text fragment, because then
79
+ * we won't be using a parse tree.
80
+ *
81
+ * @param languageId The language id, or `undefined` if in a text fragment
71
82
* @returns A list of all possible delimiters for that language
72
83
*/
73
84
export function getSimpleDelimiterMap (
74
- languageId : string ,
85
+ languageId : string | undefined ,
75
86
) : Record <
76
87
SimpleSurroundingPairName ,
77
88
[ IndividualDelimiterText , IndividualDelimiterText ]
78
89
> {
79
- if ( languageId == "nix" ) {
80
- return delimiterToTextNix ;
81
- } else if ( languageId == "lua" ) {
82
- return delimiterToTextLua ;
83
- } else {
84
- return delimiterToText ;
90
+ if ( languageId != null && languageId in delimiterToTextOverrides ) {
91
+ return {
92
+ ...delimiterToText ,
93
+ ...delimiterToTextOverrides [ languageId ] ,
94
+ } ;
85
95
}
96
+
97
+ return delimiterToText ;
86
98
}
0 commit comments