@@ -6,10 +6,12 @@ import { unsafeKeys } from "../../../util/object";
66
77type IndividualDelimiterText = string | string [ ] ;
88
9- const delimiterToText : Record <
9+ type DelimiterMap = Record <
1010 SimpleSurroundingPairName ,
1111 [ IndividualDelimiterText , IndividualDelimiterText ]
12- > = Object . freeze ( {
12+ > ;
13+
14+ const delimiterToText : DelimiterMap = Object . freeze ( {
1315 angleBrackets : [
1416 [ "</" , "<" ] ,
1517 [ ">" , "/>" ] ,
@@ -26,20 +28,22 @@ const delimiterToText: Record<
2628 squareBrackets : [ "[" , "]" ] ,
2729} ) ;
2830
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+ } ,
3637
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+ } ,
4347} ;
4448
4549export const leftToRightMap : Record < string , string > = Object . fromEntries (
@@ -65,22 +69,33 @@ export const complexDelimiterMap: Record<
6569} ;
6670
6771/**
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+ * FIXME: Probably remove these as part of
82+ * https://github.com/cursorless-dev/cursorless/issues/1812#issuecomment-1691493746
83+ *
84+ * @param languageId The language id, or `undefined` if in a text fragment
7185 * @returns A list of all possible delimiters for that language
7286 */
7387export function getSimpleDelimiterMap (
74- languageId : string ,
88+ languageId : string | undefined ,
7589) : Record <
7690 SimpleSurroundingPairName ,
7791 [ IndividualDelimiterText , IndividualDelimiterText ]
7892> {
79- if ( languageId == "nix" ) {
80- return delimiterToTextNix ;
81- } else if ( languageId == "lua" ) {
82- return delimiterToTextLua ;
83- } else {
84- return delimiterToText ;
93+ if ( languageId != null && languageId in delimiterToTextOverrides ) {
94+ return {
95+ ...delimiterToText ,
96+ ...delimiterToTextOverrides [ languageId ] ,
97+ } ;
8598 }
99+
100+ return delimiterToText ;
86101}
0 commit comments