-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsuggestionMode.js
More file actions
29 lines (23 loc) · 904 Bytes
/
suggestionMode.js
File metadata and controls
29 lines (23 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'use strict';
const VALID_MODES = new Set(['apply', 'suggest', 'auto']);
const normalize = (raw) => {
if (typeof raw !== 'string') return 'auto';
const lc = raw.toLowerCase();
return VALID_MODES.has(lc) ? lc : 'auto';
};
const resolveSuggestionMode = (padId, override, settings, depAvailable) => {
const chat = (settings && settings.chat) || {};
const padMap = chat.suggestionModePads || {};
const requested =
override != null
? normalize(override)
: padMap[padId] != null
? normalize(padMap[padId])
: normalize(chat.suggestionMode);
const desired = requested === 'auto' ? (depAvailable ? 'suggest' : 'apply') : requested;
if (desired === 'suggest' && !depAvailable) {
return {mode: 'apply', fellBackFromSuggest: true};
}
return {mode: desired, fellBackFromSuggest: false};
};
exports.resolveSuggestionMode = resolveSuggestionMode;