diff --git a/addons/isl-server/proxy/existingServerStateFiles.ts b/addons/isl-server/proxy/existingServerStateFiles.ts index 860e5a31b77ec..d01f59780e8e2 100644 --- a/addons/isl-server/proxy/existingServerStateFiles.ts +++ b/addons/isl-server/proxy/existingServerStateFiles.ts @@ -9,7 +9,7 @@ import rmtree from './rmtree'; import fs from 'fs'; import os from 'os'; import path from 'path'; -import {unwrap} from 'shared/utils'; +import {nullthrows} from 'shared/utils'; export type ExistingServerInfo = { sensitiveToken: string; @@ -28,7 +28,7 @@ export type ExistingServerInfo = { const cacheDir = process.platform == 'win32' - ? path.join(unwrap(process.env.LOCALAPPDATA), 'cache') + ? path.join(nullthrows(process.env.LOCALAPPDATA), 'cache') : process.platform == 'darwin' ? path.join(os.homedir(), 'Library/Caches') : process.env.XDG_CACHE_HOME || path.join(os.homedir(), '.cache'); diff --git a/addons/isl-server/src/Repository.ts b/addons/isl-server/src/Repository.ts index ab2feb443d95f..6b2ddd1699064 100644 --- a/addons/isl-server/src/Repository.ts +++ b/addons/isl-server/src/Repository.ts @@ -85,7 +85,7 @@ import {RateLimiter} from 'shared/RateLimiter'; import {TypedEventEmitter} from 'shared/TypedEventEmitter'; import {exists} from 'shared/fs'; import {removeLeadingPathSep} from 'shared/pathUtils'; -import {notEmpty, randomId, unwrap} from 'shared/utils'; +import {notEmpty, randomId, nullthrows} from 'shared/utils'; /** * This class is responsible for providing information about the working copy @@ -497,7 +497,7 @@ export class Repository { } private normalizeOperationArgs(cwd: string, args: Array): Array { - const repoRoot = unwrap(this.info.repoRoot); + const repoRoot = nullthrows(this.info.repoRoot); return args.flatMap(arg => { if (typeof arg === 'object') { switch (arg.type) { diff --git a/addons/isl-server/src/ServerToClientAPI.ts b/addons/isl-server/src/ServerToClientAPI.ts index e964856d040b4..66ff83e507d9b 100644 --- a/addons/isl-server/src/ServerToClientAPI.ts +++ b/addons/isl-server/src/ServerToClientAPI.ts @@ -36,7 +36,7 @@ import {repositoryCache} from './RepositoryCache'; import {findPublicAncestor, parseExecJson} from './utils'; import {serializeToString, deserializeFromString} from 'isl/src/serialize'; import {revsetForComparison} from 'shared/Comparison'; -import {randomId, unwrap} from 'shared/utils'; +import {randomId, nullthrows} from 'shared/utils'; import {Readable} from 'stream'; export type IncomingMessage = ClientToServerMessage; @@ -254,7 +254,7 @@ export default class ServerToClientAPI { } this.tracker .operation('UploadImage', 'UploadImageError', {}, () => - uploadFile(unwrap(this.connection.logger), {filename, data: payload}), + uploadFile(nullthrows(this.connection.logger), {filename, data: payload}), ) .then((result: string) => { this.connection.logger?.info('sucessfully uploaded file', filename, result); diff --git a/addons/isl-server/src/analytics/environment.ts b/addons/isl-server/src/analytics/environment.ts index d5628b5be8f7d..adda678bf0257 100644 --- a/addons/isl-server/src/analytics/environment.ts +++ b/addons/isl-server/src/analytics/environment.ts @@ -8,7 +8,7 @@ import type {ApplicationInfo} from './types'; import os from 'os'; -import {randomId, unwrap} from 'shared/utils'; +import {randomId, nullthrows} from 'shared/utils'; export function getUsername(): string { try { @@ -16,7 +16,7 @@ export function getUsername(): string { } catch (osInfoError) { try { const {env} = process; - return unwrap(env.LOGNAME || env.USER || env.LNAME || env.USERNAME); + return nullthrows(env.LOGNAME || env.USER || env.LNAME || env.USERNAME); } catch (processEnvError) { throw new Error(String(processEnvError) + String(osInfoError)); } diff --git a/addons/isl-server/src/serverPlatform.ts b/addons/isl-server/src/serverPlatform.ts index 3b41d09db35aa..359afea648238 100644 --- a/addons/isl-server/src/serverPlatform.ts +++ b/addons/isl-server/src/serverPlatform.ts @@ -15,7 +15,7 @@ import type { import {spawn} from 'child_process'; import pathModule from 'path'; -import {unwrap} from 'shared/utils'; +import {nullthrows} from 'shared/utils'; /** * Platform-specific server-side API for each target: vscode extension host, electron standalone, browser, ... @@ -43,7 +43,10 @@ export const browserServerPlatform: ServerPlatform = { ) => { switch (message.type) { case 'platform/openContainingFolder': { - const absPath: AbsolutePath = pathModule.join(unwrap(repo?.info.repoRoot), message.path); + const absPath: AbsolutePath = pathModule.join( + nullthrows(repo?.info.repoRoot), + message.path, + ); let args: Array = []; // use OS-builtin open command to open parent directory // (which may open different file extensions with different programs) diff --git a/addons/isl/src/Cleanup.tsx b/addons/isl/src/Cleanup.tsx index c30c7145bbffb..bd6a75fedc58a 100644 --- a/addons/isl/src/Cleanup.tsx +++ b/addons/isl/src/Cleanup.tsx @@ -19,7 +19,7 @@ import {type Dag, dagWithPreviews} from './previews'; import {VSCodeButton} from '@vscode/webview-ui-toolkit/react'; import {useAtomValue} from 'jotai'; import {Icon} from 'shared/Icon'; -import {unwrap} from 'shared/utils'; +import {nullthrows} from 'shared/utils'; export function isStackEligibleForCleanup( hash: Hash, @@ -99,7 +99,7 @@ export function CleanupAllButton() { contextKey="cleanup-all" runOperation={() => { return cleanableStacks.map(hash => { - const info = unwrap(dag.get(hash)); + const info = nullthrows(dag.get(hash)); return new HideOperation(latestSuccessorUnlessExplicitlyObsolete(info)); }); }} diff --git a/addons/isl/src/CommitInfoView/CommitInfoView.tsx b/addons/isl/src/CommitInfoView/CommitInfoView.tsx index d58428a24f2d3..94fe80735473e 100644 --- a/addons/isl/src/CommitInfoView/CommitInfoView.tsx +++ b/addons/isl/src/CommitInfoView/CommitInfoView.tsx @@ -87,7 +87,7 @@ import {useCallback, useEffect} from 'react'; import {ComparisonType} from 'shared/Comparison'; import {useContextMenu} from 'shared/ContextMenu'; import {Icon} from 'shared/Icon'; -import {firstLine, notEmpty, unwrap} from 'shared/utils'; +import {firstLine, notEmpty, nullthrows} from 'shared/utils'; import './CommitInfoView.css'; @@ -779,7 +779,7 @@ function ActionsBar({ answer, ); setRepoInfo(info => ({ - ...unwrap(info), + ...nullthrows(info), preferredSubmitCommand: answer, })); // setRepoInfo updates `provider`, but we still have a stale reference in this callback. @@ -802,7 +802,7 @@ function ActionsBar({ // during another amend or amend message. const shouldUpdateMessage = !isCommitMode && messageSyncEnabled && anythingToCommit; - const submitOp = unwrap(provider).submitOperation( + const submitOp = nullthrows(provider).submitOperation( commit.isHead ? [] : [commit], // [] means to submit the head commit { draft: shouldSubmitAsDraft, diff --git a/addons/isl/src/CommitInfoView/GenerateWithAI.tsx b/addons/isl/src/CommitInfoView/GenerateWithAI.tsx index 6d28a450c6593..98dca7c949c67 100644 --- a/addons/isl/src/CommitInfoView/GenerateWithAI.tsx +++ b/addons/isl/src/CommitInfoView/GenerateWithAI.tsx @@ -30,7 +30,7 @@ import {useCallback} from 'react'; import {ComparisonType} from 'shared/Comparison'; import {Icon} from 'shared/Icon'; import {useThrottledEffect} from 'shared/hooks'; -import {randomId, unwrap} from 'shared/utils'; +import {randomId, nullthrows} from 'shared/utils'; import './GenerateWithAI.css'; @@ -145,7 +145,7 @@ const generatedCommitMessages = atomFamilyWeak((hashKey: string | undefined) => const comparison: Comparison = hashKey.startsWith('commit/') ? {type: ComparisonType.UncommittedChanges} : {type: ComparisonType.Committed, hash: hashKey}; - const response = await unwrap(Internal.generateAICommitMessage)({ + const response = await nullthrows(Internal.generateAICommitMessage)({ comparison, title: latestWrittenTitle, }); @@ -296,7 +296,7 @@ class FunnelTracker { /** Get or create the funnel tracker for this hashKey */ static get(hashKey: HashKey): FunnelTracker { if (this.trackersByHashKey.has(hashKey)) { - return unwrap(this.trackersByHashKey.get(hashKey)); + return nullthrows(this.trackersByHashKey.get(hashKey)); } const tracker = new FunnelTracker(); this.trackersByHashKey.set(hashKey, tracker); diff --git a/addons/isl/src/ComparisonView/SplitDiffView/syntaxHighlighting.tsx b/addons/isl/src/ComparisonView/SplitDiffView/syntaxHighlighting.tsx index afd1b59e4c463..66c2199a8e752 100644 --- a/addons/isl/src/ComparisonView/SplitDiffView/syntaxHighlighting.tsx +++ b/addons/isl/src/ComparisonView/SplitDiffView/syntaxHighlighting.tsx @@ -22,7 +22,7 @@ import FilepathClassifier from 'shared/textmate-lib/FilepathClassifier'; import createTextMateRegistry from 'shared/textmate-lib/createTextMateRegistry'; import {updateTextMateGrammarCSS} from 'shared/textmate-lib/textmateStyles'; import {tokenizeLines} from 'shared/textmate-lib/tokenize'; -import {unwrap} from 'shared/utils'; +import {nullthrows} from 'shared/utils'; import {loadWASM} from 'vscode-oniguruma'; const URL_TO_ONIG_WASM = 'generated/textmate/onig.wasm'; @@ -208,7 +208,7 @@ async function tokenizeContent( const grammarCache: Map> = new Map(); function getGrammar(store: Registry, scopeName: string): Promise { if (grammarCache.has(scopeName)) { - return unwrap(grammarCache.get(scopeName)); + return nullthrows(grammarCache.get(scopeName)); } const grammarPromise = store.loadGrammar(scopeName); grammarCache.set(scopeName, grammarPromise); diff --git a/addons/isl/src/ConfirmSubmitStack.tsx b/addons/isl/src/ConfirmSubmitStack.tsx index e03f17c945e20..7f213e3db3f85 100644 --- a/addons/isl/src/ConfirmSubmitStack.tsx +++ b/addons/isl/src/ConfirmSubmitStack.tsx @@ -22,7 +22,7 @@ import {VSCodeDivider, VSCodeButton, VSCodeTextField} from '@vscode/webview-ui-t import {useAtom, useAtomValue} from 'jotai'; import {useState} from 'react'; import {useAutofocusRef} from 'shared/hooks'; -import {unwrap} from 'shared/utils'; +import {nullthrows} from 'shared/utils'; import './ConfirmSubmitStack.css'; @@ -66,7 +66,10 @@ export function useShowConfirmSubmitStack() { const provider = readAtom(codeReviewProvider); - const replace = {$numCommits: String(stack.length), $cmd: unwrap(provider).submitCommandName()}; + const replace = { + $numCommits: String(stack.length), + $cmd: nullthrows(provider).submitCommandName(), + }; const title = mode === 'submit' ? t('Submitting $numCommits commits for review with $cmd', {replace}) diff --git a/addons/isl/src/DownloadCommitsMenu.tsx b/addons/isl/src/DownloadCommitsMenu.tsx index 0c981341a076c..9493fa18289fd 100644 --- a/addons/isl/src/DownloadCommitsMenu.tsx +++ b/addons/isl/src/DownloadCommitsMenu.tsx @@ -29,7 +29,7 @@ import {useAtom} from 'jotai'; import {useEffect, useRef, useState} from 'react'; import {Icon} from 'shared/Icon'; import {KeyCode, Modifier} from 'shared/KeyboardShortcuts'; -import {unwrap} from 'shared/utils'; +import {nullthrows} from 'shared/utils'; import './DownloadCommitsMenu.css'; @@ -128,7 +128,7 @@ function DownloadCommitsTooltip({dismiss}: {dismiss: () => unknown}) { const dest = rebaseType === 'rebase_ontop' ? '.' - : unwrap(findCurrentPublicBase(readAtom(dagWithPreviews))?.hash); + : nullthrows(findCurrentPublicBase(readAtom(dagWithPreviews))?.hash); // Use exact revsets for sources, so that you can type a specific hash to download and not be surprised by succession. // Only use succession for destination, which may be in flux at the moment you start the download. runOperation(new Op(exactRevset(enteredDiffNum), succeedableRevset(dest))); diff --git a/addons/isl/src/SettingsTooltip.tsx b/addons/isl/src/SettingsTooltip.tsx index 8f14cb166b2fb..7fdc05c9202ae 100644 --- a/addons/isl/src/SettingsTooltip.tsx +++ b/addons/isl/src/SettingsTooltip.tsx @@ -39,7 +39,7 @@ import { import {useAtom, useAtomValue} from 'jotai'; import {Icon} from 'shared/Icon'; import {KeyCode, Modifier} from 'shared/KeyboardShortcuts'; -import {tryJsonParse, unwrap} from 'shared/utils'; +import {tryJsonParse, nullthrows} from 'shared/utils'; import './VSCodeDropdown.css'; import './SettingsTooltip.css'; @@ -159,7 +159,7 @@ function SettingsDropdown({ runOperation( new SetConfigOperation('local', 'github.preferred_submit_command', value), ); - setRepoInfo(info => ({...unwrap(info), preferredSubmitCommand: value})); + setRepoInfo(info => ({...nullthrows(info), preferredSubmitCommand: value})); }}> {repoInfo.preferredSubmitCommand == null ? ( (not set) diff --git a/addons/isl/src/__tests__/ComparisonView.test.tsx b/addons/isl/src/__tests__/ComparisonView.test.tsx index 048c8f66b3cd4..34cabbbe1bf2b 100644 --- a/addons/isl/src/__tests__/ComparisonView.test.tsx +++ b/addons/isl/src/__tests__/ComparisonView.test.tsx @@ -26,7 +26,7 @@ import fs from 'fs'; import path from 'path'; import {ComparisonType} from 'shared/Comparison'; import {nextTick} from 'shared/testUtils'; -import {unwrap} from 'shared/utils'; +import {nullthrows} from 'shared/utils'; afterEach(cleanup); @@ -594,7 +594,7 @@ function mockFetchToSupportSyntaxHighlighting(): jest.SpyInstance { jest.fn(async url => { if (url.includes('generated/textmate')) { const match = /.*generated\/textmate\/(.*)$/.exec(url); - const filename = unwrap(match)[1]; + const filename = nullthrows(match)[1]; const toPublicDir = (filename: string) => path.normalize(path.join(__dirname, '../../public/generated/textmate', filename)); if (filename === 'onig.wasm') { diff --git a/addons/isl/src/__tests__/FillCommitMessage.test.tsx b/addons/isl/src/__tests__/FillCommitMessage.test.tsx index e958108769199..c84d214fab1c8 100644 --- a/addons/isl/src/__tests__/FillCommitMessage.test.tsx +++ b/addons/isl/src/__tests__/FillCommitMessage.test.tsx @@ -18,7 +18,7 @@ import { import {fireEvent, render, screen, waitFor, within} from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import {act} from 'react-dom/test-utils'; -import {unwrap} from 'shared/utils'; +import {nullthrows} from 'shared/utils'; /* eslint-disable @typescript-eslint/no-non-null-assertion */ @@ -110,7 +110,7 @@ describe('FillCommitMessage', () => { expect(loadFromLastCommit).toBeInTheDocument(); fireEvent.click(loadFromLastCommit); await waitFor(() => expect(getTitleEditor().value).toMatch('Head Commit')); - expect(getFieldEditor(unwrap(Internal.diffFieldTag))).toHaveValue(''); + expect(getFieldEditor(nullthrows(Internal.diffFieldTag))).toHaveValue(''); }); it('Load from commit template', async () => { diff --git a/addons/isl/src/__tests__/Shelve.test.tsx b/addons/isl/src/__tests__/Shelve.test.tsx index 8160d65354c8c..974603bd7459d 100644 --- a/addons/isl/src/__tests__/Shelve.test.tsx +++ b/addons/isl/src/__tests__/Shelve.test.tsx @@ -21,7 +21,7 @@ import {fireEvent, render, screen, waitFor, within} from '@testing-library/react import userEvent from '@testing-library/user-event'; import {act} from 'react-dom/test-utils'; import {ComparisonType} from 'shared/Comparison'; -import {unwrap} from 'shared/utils'; +import {nullthrows} from 'shared/utils'; describe('Shelve', () => { beforeEach(() => { @@ -99,7 +99,7 @@ describe('Shelve', () => { // uncheck one file fireEvent.click( - unwrap( + nullthrows( screen.getByTestId('changed-file-src/file2.js').querySelector('input[type=checkbox]'), ), ); diff --git a/addons/isl/src/codeReview/CodeReviewInfo.ts b/addons/isl/src/codeReview/CodeReviewInfo.ts index c49fc7e07a555..9d6537eea88cb 100644 --- a/addons/isl/src/codeReview/CodeReviewInfo.ts +++ b/addons/isl/src/codeReview/CodeReviewInfo.ts @@ -27,7 +27,7 @@ import {GithubUICodeReviewProvider} from './github/github'; import {atom} from 'jotai'; import {clearTrackedCache} from 'shared/LRU'; import {debounce} from 'shared/debounce'; -import {firstLine, unwrap} from 'shared/utils'; +import {firstLine, nullthrows} from 'shared/utils'; export const codeReviewProvider = atom(get => { const repoInfo = get(repositoryInfo); @@ -88,7 +88,10 @@ registerDisposable( // merge old values with newly fetched ones return { - value: new Map([...unwrap(existing.value).entries(), ...event.summaries.value.entries()]), + value: new Map([ + ...nullthrows(existing.value).entries(), + ...event.summaries.value.entries(), + ]), }; }); }), diff --git a/addons/isl/src/dag/base_dag.ts b/addons/isl/src/dag/base_dag.ts index 3094eab00e68e..54bdfd26c2f2d 100644 --- a/addons/isl/src/dag/base_dag.ts +++ b/addons/isl/src/dag/base_dag.ts @@ -13,7 +13,7 @@ import {HashSet} from './set'; import {Map as ImMap, Record, List} from 'immutable'; import {LRU, cachedMethod} from 'shared/LRU'; import {SelfUpdate} from 'shared/immutableExt'; -import {unwrap} from 'shared/utils'; +import {nullthrows} from 'shared/utils'; /** * Hash-map like container with graph related queries. @@ -263,7 +263,8 @@ export class BaseDag extends SelfUpdate(); // We use concat and pop (not unshift) so the order is reversed. - const compareHash = (a: Hash, b: Hash) => -compare(unwrap(this.get(a)), unwrap(this.get(b))); + const compareHash = (a: Hash, b: Hash) => + -compare(nullthrows(this.get(a)), nullthrows(this.get(b))); // The number of parents remaining to be visited. This ensures merges are not // outputted until all parents are outputted. const remaining = new Map( diff --git a/addons/isl/src/dag/dag.ts b/addons/isl/src/dag/dag.ts index 2e3d35ea7aee5..d2d45c23beef0 100644 --- a/addons/isl/src/dag/dag.ts +++ b/addons/isl/src/dag/dag.ts @@ -20,7 +20,7 @@ import {arrayFromHashes, HashSet} from './set'; import {List, Record, Map as ImMap, Set as ImSet} from 'immutable'; import {LRU, cachedMethod} from 'shared/LRU'; import {SelfUpdate} from 'shared/immutableExt'; -import {group, notEmpty, splitOnce, unwrap} from 'shared/utils'; +import {group, notEmpty, splitOnce, nullthrows} from 'shared/utils'; /** * Main commit graph type used for preview calculation and queries. @@ -369,7 +369,7 @@ export class Dag extends SelfUpdate { const pureHash = isSucc ? h.substring(REBASE_SUCC_PREFIX.length) : h; const isPred = !isSucc && duplicated.contains(h); const isRoot = srcRoots.contains(pureHash); - const info = unwrap(isSucc ? this.get(pureHash) : c); + const info = nullthrows(isSucc ? this.get(pureHash) : c); return info.withMutations(mut => { // Reset the seqNumber so the rebase preview tends to show as right-most branches. let newInfo = mut.set('seqNumber', undefined); @@ -565,7 +565,7 @@ export class Dag extends SelfUpdate { // Render row by row. The main complexity is to figure out the "ancestors", // especially when the provided `set` is a subset of the dag. for (const hash of sorted) { - const info = unwrap(this.get(hash)); + const info = nullthrows(this.get(hash)); const parents: ReadonlyArray = info?.parents ?? []; // directParents: solid edges // indirectParents: dashed edges diff --git a/addons/isl/src/linelog.ts b/addons/isl/src/linelog.ts index 73af4f32cd83a..c5bdeeb17f615 100644 --- a/addons/isl/src/linelog.ts +++ b/addons/isl/src/linelog.ts @@ -37,7 +37,7 @@ import {hash, List, Record, Set as ImSet} from 'immutable'; import {cached, cachedMethod, LRU} from 'shared/LRU'; import {diffLines, splitLines} from 'shared/diff'; import {SelfUpdate} from 'shared/immutableExt'; -import {unwrap} from 'shared/utils'; +import {nullthrows} from 'shared/utils'; /** Operation code. */ enum Op { @@ -378,7 +378,7 @@ class Code implements ValueObject { if (aLinesMutable) { aLines[a1] = {...aLines[a1], pc: jlInst == null ? code.size : code.size + 1}; } - const a1Inst = unwrap(code.get(a1Pc)); + const a1Inst = nullthrows(code.get(a1Pc)); if (jlInst === undefined) { // [3] code = code.push(a1Inst); @@ -551,7 +551,7 @@ class Code implements ValueObject { delStack.pop(); onStackPop?.(delStack); } - const code = unwrap(this.get(pc)); + const code = nullthrows(this.get(pc)); switch (code.op) { case Op.LINE: onLine?.(code); @@ -898,7 +898,7 @@ class LineLog extends SelfUpdate { let patience = this.code.getSize() * 2; const deleted = present == null ? () => false : (pc: Pc) => !present[pc]; while (patience > 0) { - const code = unwrap(this.code.get(pc)); + const code = nullthrows(this.code.get(pc)); switch (code.op) { case Op.END: lines.push({data: '', rev: 0, pc, deleted: deleted(pc)}); diff --git a/addons/isl/src/platform/__tests__/webviewPlatform.test.ts b/addons/isl/src/platform/__tests__/webviewPlatform.test.ts index 301ac17c0280a..86579e1e13360 100644 --- a/addons/isl/src/platform/__tests__/webviewPlatform.test.ts +++ b/addons/isl/src/platform/__tests__/webviewPlatform.test.ts @@ -6,7 +6,7 @@ */ import {webviewPlatform} from '../webviewPlatform'; -import {unwrap} from 'shared/utils'; +import {nullthrows} from 'shared/utils'; (window.external as unknown as Record).invoke = jest.fn(); @@ -39,7 +39,7 @@ describe('webview platform', () => { id: 1, }); - const result = unwrap(await promise); + const result = nullthrows(await promise); expect(result[0].name).toEqual('file.txt'); expect(await result[0].size).toEqual(5); }); diff --git a/addons/isl/src/previews.ts b/addons/isl/src/previews.ts index 18992ada148c5..acff8411b0fc5 100644 --- a/addons/isl/src/previews.ts +++ b/addons/isl/src/previews.ts @@ -27,7 +27,7 @@ import { } from './serverAPIState'; import {atom, useAtom, useAtomValue} from 'jotai'; import {useEffect} from 'react'; -import {notEmpty, unwrap} from 'shared/utils'; +import {notEmpty, nullthrows} from 'shared/utils'; export enum CommitPreview { REBASE_ROOT = 'rebase-root', @@ -402,7 +402,7 @@ export function useMarkOperationsCompleted(): void { if (optimisticApplier == null || operation.exitCode !== 0) { files = true; } else if ( - uncommittedChanges.fetchStartTimestamp > unwrap(operation.endTime).valueOf() + uncommittedChanges.fetchStartTimestamp > nullthrows(operation.endTime).valueOf() ) { getTracker()?.track('OptimisticFilesStateForceResolved', {extras: {}}); files = true; @@ -422,7 +422,7 @@ export function useMarkOperationsCompleted(): void { conflicts = true; } else if ( (mergeConflictsContext.conflicts?.fetchStartTimestamp ?? 0) > - unwrap(operation.endTime).valueOf() + nullthrows(operation.endTime).valueOf() ) { getTracker()?.track('OptimisticConflictsStateForceResolved', { extras: {operation: getOpName(operation.operation)}, diff --git a/addons/isl/src/stackEdit/__tests__/commitStackState.test.ts b/addons/isl/src/stackEdit/__tests__/commitStackState.test.ts index 82a8680e8ec9e..57a8c7b153ba5 100644 --- a/addons/isl/src/stackEdit/__tests__/commitStackState.test.ts +++ b/addons/isl/src/stackEdit/__tests__/commitStackState.test.ts @@ -11,7 +11,7 @@ import type {ExportCommit, ExportStack} from 'shared/types/stack'; import {ABSENT_FILE, CommitIdx, CommitStackState, CommitState} from '../commitStackState'; import {FileStackState} from '../fileStackState'; import {List, Set as ImSet, Map as ImMap} from 'immutable'; -import {unwrap} from 'shared/utils'; +import {nullthrows} from 'shared/utils'; const exportCommitDefault: ExportCommit = { requested: true, @@ -882,7 +882,7 @@ describe('CommitStackState', () => { const emptyStack = subStack.set('stack', List()); const getChangedFiles = (state: CommitStackState, rev: Rev): Array => { - return [...unwrap(state.stack.get(rev)).files.keys()].sort(); + return [...nullthrows(state.stack.get(rev)).files.keys()].sort(); }; it('optimizes file changes by removing unmodified changes', () => { @@ -900,7 +900,7 @@ describe('CommitStackState', () => { // Change the 2nd commit in subStack to empty. const newSubStack = subStack.set( 'stack', - subStack.stack.setIn([1, 'files'], unwrap(subStack.stack.get(0)).files), + subStack.stack.setIn([1, 'files'], nullthrows(subStack.stack.get(0)).files), ); // `applySubStack` should drop the 2nd commit in `newSubStack`. const newStack = stack.applySubStack(2, 4, newSubStack); @@ -947,7 +947,7 @@ describe('CommitStackState', () => { }); it('update keys to avoid conflict', () => { - const oldKey = unwrap(stack.stack.get(1)).key; + const oldKey = nullthrows(stack.stack.get(1)).key; const newSubStack = subStack.set('stack', subStack.stack.setIn([0, 'key'], oldKey)); const newStack = stack.applySubStack(2, 3, newSubStack); @@ -961,8 +961,10 @@ describe('CommitStackState', () => { // x.txt was deleted by subStack rev 0 (B). We are moving it to be deleted by rev 1 (C). expect(subStack.getFile(0, 'x.txt').flags).toBe(ABSENT_FILE.flags); // To break the deletion into done by 2 commits, we edit the file stack of 'x.txt'. - const fileIdx = unwrap(subStack.commitToFile.get(CommitIdx({rev: 0, path: 'x.txt'}))).fileIdx; - const fileStack = unwrap(subStack.fileStacks.get(fileIdx)); + const fileIdx = nullthrows( + subStack.commitToFile.get(CommitIdx({rev: 0, path: 'x.txt'})), + ).fileIdx; + const fileStack = nullthrows(subStack.fileStacks.get(fileIdx)); // The file stack has 3 revs: (base, before deletion), (deleted at rev 0), (deleted at rev 1). expect(fileStack.convertToPlainText().toArray()).toEqual(['33', '', '']); const newFileStack = new FileStackState(['33', '3', '']); @@ -993,8 +995,10 @@ describe('CommitStackState', () => { it('does not add ABSENT flag if content becomes empty', () => { // This was a herustics when `flags` are not handled properly. Now it is no longer needed. // y.txt was added by subStack rev 0 (B). We are moving it to be added by rev 1 (C). - const fileIdx = unwrap(subStack.commitToFile.get(CommitIdx({rev: 0, path: 'y.txt'}))).fileIdx; - const fileStack = unwrap(subStack.fileStacks.get(fileIdx)); + const fileIdx = nullthrows( + subStack.commitToFile.get(CommitIdx({rev: 0, path: 'y.txt'})), + ).fileIdx; + const fileStack = nullthrows(subStack.fileStacks.get(fileIdx)); // The file stack has 3 revs: (base, before add), (add by rev 0), (unchanged by rev 1). expect(fileStack.convertToPlainText().toArray()).toEqual(['', '33', '33']); const newFileStack = new FileStackState(['', '', '33']); diff --git a/addons/isl/src/stackEdit/commitStackState.ts b/addons/isl/src/stackEdit/commitStackState.ts index 90dae1dd06eed..3ca6ef49d0641 100644 --- a/addons/isl/src/stackEdit/commitStackState.ts +++ b/addons/isl/src/stackEdit/commitStackState.ts @@ -30,7 +30,7 @@ import deepEqual from 'fast-deep-equal'; import {Seq, List, Map as ImMap, Set as ImSet, Record, is} from 'immutable'; import {LRU, cachedMethod} from 'shared/LRU'; import {SelfUpdate} from 'shared/immutableExt'; -import {firstLine, generatorContains, unwrap, zip} from 'shared/utils'; +import {firstLine, generatorContains, nullthrows, zip} from 'shared/utils'; type CommitStackProps = { /** @@ -407,9 +407,9 @@ export class CommitStackState extends SelfUpdate { if (changedRevs.has(rev)) { return revToMark(rev); } else { - const nodes = unwrap(state.stack.get(rev)).originalNodes; + const nodes = nullthrows(state.stack.get(rev)).originalNodes; assert(nodes.size === 1, 'unchanged commits should have exactly 1 nodes'); - return unwrap(nodes.first()); + return nullthrows(nodes.first()); } }; @@ -485,7 +485,7 @@ export class CommitStackState extends SelfUpdate { parentFile(rev: Rev, path: RepoPath, followRenames = true): [Rev, RepoPath, FileState] { let prevRev = -1; let prevPath = path; - let prevFile = unwrap(this.bottomFiles.get(path)); + let prevFile = nullthrows(this.bottomFiles.get(path)); const includeBottom = true; const logFile = this.logFile(rev, path, followRenames, includeBottom); for (const [logRev, logPath, file] of logFile) { @@ -716,7 +716,7 @@ export class CommitStackState extends SelfUpdate { : ((c: CommitState): [string, boolean] => [ c.text.split('\n').at(0) || [...c.originalNodes].at(0) || '?', isAbsent(c.files.get(path)), - ])(unwrap(stack.get(rev))); + ])(nullthrows(stack.get(rev))); spans.push(`${commitTitle}/${path}`); if (showContent && !absent) { spans.push(`(${fileStack.getRev(fileRev)})`); @@ -730,7 +730,7 @@ export class CommitStackState extends SelfUpdate { /** File name for `fileStacks[index]`. If the file is renamed, return */ getFileStackDescription(fileIdx: number): string { - const fileStack = unwrap(this.fileStacks.get(fileIdx)); + const fileStack = nullthrows(this.fileStacks.get(fileIdx)); const revLength = fileStack.revLength - 1; const nameAtFirstRev = this.getFileStackPath(fileIdx, 0); const nameAtLastRev = this.getFileStackPath(fileIdx, revLength - 1); @@ -763,7 +763,7 @@ export class CommitStackState extends SelfUpdate { if (commitRev == null || commitRev < 0) { return undefined; } - return unwrap(this.stack.get(commitRev)); + return nullthrows(this.stack.get(commitRev)); } /** @@ -785,7 +785,7 @@ export class CommitStackState extends SelfUpdate { return file.data; } if (file.data instanceof FileIdx) { - return unwrap(this.fileStacks.get(file.data.fileIdx)).getRev(file.data.fileRev); + return nullthrows(this.fileStacks.get(file.data.fileIdx)).getRev(file.data.fileRev); } else { throw new Error('getUtf8Data called on non-utf8 file.'); } @@ -848,7 +848,7 @@ export class CommitStackState extends SelfUpdate { const depMap = new Map>(state.stack.map(c => [c.rev, new Set()])); const fileIdxRevToCommitRev = (fileIdx: FileStackIndex, fileRev: Rev): Rev => - unwrap(state.fileToCommit.get(FileIdx({fileIdx, fileRev}))).rev; + nullthrows(state.fileToCommit.get(FileIdx({fileIdx, fileRev}))).rev; // Ask FileStack for dependencies about content edits. state.fileStacks.forEach((fileStack, fileIdx) => { @@ -858,7 +858,7 @@ export class CommitStackState extends SelfUpdate { fileDepMap.forEach((valueFileRevs, keyFileRev) => { const keyCommitRev = toCommitRev(keyFileRev); if (keyCommitRev >= 0) { - const set = unwrap(depMap.get(keyCommitRev)); + const set = nullthrows(depMap.get(keyCommitRev)); valueFileRevs.forEach(fileRev => { const rev = toCommitRev(fileRev); if (rev >= 0) { @@ -871,7 +871,7 @@ export class CommitStackState extends SelfUpdate { // Besides, file deletion / addition / renames also introduce dependencies. state.stack.forEach(commit => { - const set = unwrap(depMap.get(commit.rev)); + const set = nullthrows(depMap.get(commit.rev)); commit.files.forEach((file, path) => { const [prevRev, prevPath, prevFile] = state.parentFile(commit.rev, path, true); if (prevRev >= 0 && (isAbsent(prevFile) !== isAbsent(file) || prevPath !== path)) { @@ -912,7 +912,7 @@ export class CommitStackState extends SelfUpdate { if (parentRev == null) { return false; } - const parent = unwrap(this.stack.get(parentRev)); + const parent = nullthrows(this.stack.get(parentRev)); if (commit.immutableKind !== 'none' || parent.immutableKind !== 'none') { return false; } @@ -942,9 +942,9 @@ export class CommitStackState extends SelfUpdate { * This should only be called when `canFoldDown(rev)` returned `true`. */ foldDown(rev: Rev) { - const commit = unwrap(this.stack.get(rev)); - const parentRev = unwrap(this.singleParentRev(rev)); - const parent = unwrap(this.stack.get(parentRev)); + const commit = nullthrows(this.stack.get(rev)); + const parentRev = nullthrows(this.singleParentRev(rev)); + const parent = nullthrows(this.stack.get(parentRev)); let newParentFiles = parent.files; const newFiles = commit.files.map((origFile, path) => { // Fold copyFrom. `-` means "no change". @@ -1037,12 +1037,12 @@ export class CommitStackState extends SelfUpdate { */ drop(rev: Rev): CommitStackState { let state = this.useFileStack().inner; - const commit = unwrap(state.stack.get(rev)); + const commit = nullthrows(state.stack.get(rev)); commit.files.forEach((file, path) => { const fileIdxRev: FileIdx | undefined = state.commitToFile.get(CommitIdx({rev, path})); if (fileIdxRev != null) { const {fileIdx, fileRev} = fileIdxRev; - const fileStack = unwrap(state.fileStacks.get(fileIdx)); + const fileStack = nullthrows(state.fileStacks.get(fileIdx)); // Drop the rev by remapping it to an unused rev. const unusedFileRev = fileStack.source.revLength; const newFileStack = fileStack.remapRevs(new Map([[fileRev, unusedFileRev]])); @@ -1079,7 +1079,7 @@ export class CommitStackState extends SelfUpdate { ); } else { const revMapFunc = (r: Rev) => (r >= rev ? r + 1 : r); - const origParents = unwrap(state.stack.get(rev)).parents; + const origParents = nullthrows(state.stack.get(rev)).parents; newStack = state.stack .map(c => rewriteCommitRevs(c, revMapFunc)) .flatMap(c => { @@ -1217,7 +1217,7 @@ export class CommitStackState extends SelfUpdate { // file revs => commit revs => mapped commit revs => mapped file revs const fileRevs = fileStack.revs(); const commitRevPaths: CommitIdx[] = fileRevs.map(fileRev => - unwrap(state.fileToCommit.get(FileIdx({fileIdx, fileRev}))), + nullthrows(state.fileToCommit.get(FileIdx({fileIdx, fileRev}))), ); const commitRevs: Rev[] = commitRevPaths.map(({rev}) => rev); const mappedCommitRevs: Rev[] = commitRevs.map(rev => commitRevMap.get(rev) ?? rev); @@ -1239,7 +1239,7 @@ export class CommitStackState extends SelfUpdate { // Update state.stack. const newStack = state.stack.map((_commit, rev) => { - const commit = unwrap(state.stack.get(order[rev])); + const commit = nullthrows(state.stack.get(order[rev])); return commit.merge({parents: List(rev > 0 ? [rev - 1] : []), rev}); }); state = state.set('stack', newStack); @@ -1549,7 +1549,7 @@ function convertExportFileToFileState(file: ExportFile | null): FileState { ? file.data : file.dataBase85 ? Base85({dataBase85: file.dataBase85}) - : DataRef(unwrap(file.dataRef)), + : DataRef(nullthrows(file.dataRef)), copyFrom: file.copyFrom, flags: file.flags, }); diff --git a/addons/isl/src/stackEdit/ui/FileStackEditPanel.tsx b/addons/isl/src/stackEdit/ui/FileStackEditPanel.tsx index 07ca232e560e9..eec95a931d01e 100644 --- a/addons/isl/src/stackEdit/ui/FileStackEditPanel.tsx +++ b/addons/isl/src/stackEdit/ui/FileStackEditPanel.tsx @@ -23,7 +23,7 @@ import { } from '@vscode/webview-ui-toolkit/react'; import {atom, useAtom} from 'jotai'; import {useState} from 'react'; -import {unwrap} from 'shared/utils'; +import {nullthrows} from 'shared/utils'; import './VSCodeDropdown.css'; @@ -94,7 +94,7 @@ export default function FileStackEditPanel() { } // Properties for file stack editing. - const stack = unwrap(commitStack.fileStacks.get(fileIdx)); + const stack = nullthrows(commitStack.fileStacks.get(fileIdx)); const getTitle = (rev: Rev) => commitStack.getCommitFromFileStackRev(fileIdx, rev)?.text ?? t( diff --git a/addons/isl/src/stackEdit/ui/FileStackEditor.tsx b/addons/isl/src/stackEdit/ui/FileStackEditor.tsx index 77526a3f343d2..f63531309b0b6 100644 --- a/addons/isl/src/stackEdit/ui/FileStackEditor.tsx +++ b/addons/isl/src/stackEdit/ui/FileStackEditor.tsx @@ -20,7 +20,7 @@ import deepEqual from 'fast-deep-equal'; import {Set as ImSet, Range, List} from 'immutable'; import React, {useState, useRef, useEffect, useLayoutEffect} from 'react'; import {mergeBlocks, collapseContextBlocks, diffBlocks, splitLines} from 'shared/diff'; -import {unwrap} from 'shared/utils'; +import {nullthrows} from 'shared/utils'; import './FileStackEditor.css'; @@ -89,7 +89,7 @@ export function FileStackEditor(props: EditorProps) { for (const div of divs) { const child = div.lastChild; if (child && selection.containsNode(child, true)) { - selIds.push(unwrap(div.dataset.selId)); + selIds.push(nullthrows(div.dataset.selId)); } } setSelectedLineIds(ImSet(selIds)); @@ -372,14 +372,14 @@ function FileStackEditorUnifiedStack(props: EditorRowProps) { ); if (textEdit) { - const len = Range(b1, b2).reduce((acc, i) => acc + unwrap(lines.get(i)).data.length, 0); + const len = Range(b1, b2).reduce((acc, i) => acc + nullthrows(lines.get(i)).data.length, 0); nextRangeId(len); } return; } for (let i = b1; i < b2; ++i) { - const line = unwrap(lines.get(i)); + const line = nullthrows(lines.get(i)); const checkboxes = revs.map(rev => { const checked = line.revs.contains(rev); let className = 'checkbox' + (rev > 0 ? ' mutable' : ' immutable'); diff --git a/addons/isl/src/stackEdit/ui/SplitStackEditPanel.tsx b/addons/isl/src/stackEdit/ui/SplitStackEditPanel.tsx index 0fd7a1786980b..fdce36b2718be 100644 --- a/addons/isl/src/stackEdit/ui/SplitStackEditPanel.tsx +++ b/addons/isl/src/stackEdit/ui/SplitStackEditPanel.tsx @@ -39,7 +39,7 @@ import {useContextMenu} from 'shared/ContextMenu'; import {Icon} from 'shared/Icon'; import {type LineIdx, splitLines, diffBlocks} from 'shared/diff'; import {useThrottledEffect} from 'shared/hooks'; -import {firstLine, unwrap} from 'shared/utils'; +import {firstLine, nullthrows} from 'shared/utils'; import './SplitStackEditPanel.css'; @@ -580,7 +580,7 @@ function StackRangeSelector() { const selectEnd = orderedDrag.end ?? selectStart; const commits = mutableRevs.map(rev => { - const commit = unwrap(commitStack.get(rev)); + const commit = nullthrows(commitStack.get(rev)); return (
{ @@ -588,7 +588,7 @@ function StackRangeSelector() { }} onPointerEnter={() => { if (dragSelection?.isDragging === true) { - setDragSelection(old => ({...unwrap(old), end: rev, endKey: commit.key})); + setDragSelection(old => ({...nullthrows(old), end: rev, endKey: commit.key})); } }} key={rev} @@ -783,7 +783,7 @@ export function SplitFile(props: SplitFileProps) { for (const div of divs) { const child = div.lastChild; if (child && selection.containsNode(child, true)) { - selIds.push(unwrap(div.dataset.selId)); + selIds.push(nullthrows(div.dataset.selId)); } } diff --git a/addons/isl/src/stackEdit/ui/StackEditSubTree.tsx b/addons/isl/src/stackEdit/ui/StackEditSubTree.tsx index 2637f6b13320b..9b19399f4372a 100644 --- a/addons/isl/src/stackEdit/ui/StackEditSubTree.tsx +++ b/addons/isl/src/stackEdit/ui/StackEditSubTree.tsx @@ -24,7 +24,7 @@ import {VSCodeButton} from '@vscode/webview-ui-toolkit/react'; import {is} from 'immutable'; import {useRef, useState} from 'react'; import {Icon} from 'shared/Icon'; -import {unwrap} from 'shared/utils'; +import {nullthrows} from 'shared/utils'; import {getZoomLevel} from 'shared/zoom'; import './StackEditSubTree.css'; @@ -102,7 +102,7 @@ export function StackEditSubTree(props: ActivateSplitProps): React.ReactElement name: 'move', offset: currentReorderState.offset, depCount: currentReorderState.draggingRevs.size - 1, - commit: unwrap(commitStack.stack.get(currentReorderState.draggingRev)), + commit: nullthrows(commitStack.stack.get(currentReorderState.draggingRev)), }); bumpStackEditMetric('moveDnD'); } @@ -168,7 +168,7 @@ export function StackEditCommit({ const canDrop = state.canDrop(rev); const canMoveDown = state.canMoveDown(rev); const canMoveUp = state.canMoveUp(rev); - const commit = unwrap(state.stack.get(rev)); + const commit = nullthrows(state.stack.get(rev)); const titleText = commit.text.split('\n', 1).at(0) ?? ''; const handleMoveUp = () => { @@ -299,7 +299,7 @@ function calculateReorderOffset( invisibleRevCount = 1, ): number { let belowCount = 0; - const parentY: number = unwrap(container).getBoundingClientRect().y; + const parentY: number = nullthrows(container).getBoundingClientRect().y; container.querySelectorAll('.commit').forEach(element => { const commitDiv = element as HTMLDivElement; // commitDiv.getBoundingClientRect() will consider the animation transform. diff --git a/addons/isl/src/stackEdit/ui/stackEditState.ts b/addons/isl/src/stackEdit/ui/stackEditState.ts index c870ac9c397e3..40e6783ddb28c 100644 --- a/addons/isl/src/stackEdit/ui/stackEditState.ts +++ b/addons/isl/src/stackEdit/ui/stackEditState.ts @@ -22,7 +22,7 @@ import {CommitStackState} from '../../stackEdit/commitStackState'; import {assert, registerDisposable} from '../../utils'; import {List, Record} from 'immutable'; import {atom, useAtom} from 'jotai'; -import {unwrap} from 'shared/utils'; +import {nullthrows} from 'shared/utils'; type StackStateWithOperationProps = { op: StackEditOpDescription; @@ -83,7 +83,7 @@ type HistoryRecord = RecordOf; class History extends HistoryRecord { get current(): StackStateWithOperation { - return unwrap(this.history.get(this.currentIndex)); + return nullthrows(this.history.get(this.currentIndex)); } push( diff --git a/addons/isl/src/testQueries.ts b/addons/isl/src/testQueries.ts index 052fd7ce19875..f4ee40b5ecc3c 100644 --- a/addons/isl/src/testQueries.ts +++ b/addons/isl/src/testQueries.ts @@ -14,7 +14,7 @@ import { import {readAtom} from './jotaiUtils'; import {screen, within, fireEvent, waitFor} from '@testing-library/react'; import {act} from 'react-dom/test-utils'; -import {unwrap} from 'shared/utils'; +import {nullthrows} from 'shared/utils'; export const CommitTreeListTestUtils = { withinCommitTree() { @@ -49,7 +49,7 @@ export const CommitInfoTestUtils = { const commit = within(screen.getByTestId(`commit-${hash}`)).queryByTestId('draggable-commit'); expect(commit).toBeInTheDocument(); act(() => { - fireEvent.click(unwrap(commit), {metaKey: cmdClick === true}); + fireEvent.click(nullthrows(commit), {metaKey: cmdClick === true}); }); }, @@ -77,7 +77,7 @@ export const CommitInfoTestUtils = { ).queryByText('Amend'); expect(amendButton).toBeInTheDocument(); act(() => { - fireEvent.click(unwrap(amendButton)); + fireEvent.click(nullthrows(amendButton)); }); }, @@ -87,7 +87,7 @@ export const CommitInfoTestUtils = { ).queryByText('Amend Message'); expect(amendMessageButton).toBeInTheDocument(); act(() => { - fireEvent.click(unwrap(amendMessageButton)); + fireEvent.click(nullthrows(amendMessageButton)); }); }, @@ -97,7 +97,7 @@ export const CommitInfoTestUtils = { ).queryByText('Commit'); expect(commitButton).toBeInTheDocument(); act(() => { - fireEvent.click(unwrap(commitButton)); + fireEvent.click(nullthrows(commitButton)); }); }, @@ -107,7 +107,7 @@ export const CommitInfoTestUtils = { expect(cancelButton).toBeInTheDocument(); act(() => { - fireEvent.click(unwrap(cancelButton)); + fireEvent.click(nullthrows(cancelButton)); }); }, diff --git a/addons/shared/utils.ts b/addons/shared/utils.ts index 79b957c2ccacd..219c0986e7733 100644 --- a/addons/shared/utils.ts +++ b/addons/shared/utils.ts @@ -14,7 +14,7 @@ export function notEmpty(value: T | null | undefined): value is T { /** * Throw if value is `null` or `undefined`. */ -export function unwrap(value: T | undefined | null): T { +export function nullthrows(value: T | undefined | null): T { if (value == null) { throw new Error(`expected value not to be ${value}`); } diff --git a/addons/vscode/extension/__tests__/DiffContentProvider.test.ts b/addons/vscode/extension/__tests__/DiffContentProvider.test.ts index f25bf7e9a9edc..59e72c961b207 100644 --- a/addons/vscode/extension/__tests__/DiffContentProvider.test.ts +++ b/addons/vscode/extension/__tests__/DiffContentProvider.test.ts @@ -18,7 +18,7 @@ import { import {makeServerSideTracker} from 'isl-server/src/analytics/serverSideTracker'; import {ComparisonType} from 'shared/Comparison'; import {mockLogger} from 'shared/testUtils'; -import {unwrap} from 'shared/utils'; +import {nullthrows} from 'shared/utils'; import * as vscode from 'vscode'; const mockCancelToken = {} as vscode.CancellationToken; @@ -72,8 +72,8 @@ function mockRepoAdded(): NonNullable { savedOnChangeHeadCommit(commit); }, } as unknown as typeof activeRepo; - activeReposCallback?.([unwrap(activeRepo)]); - return unwrap(activeRepo); + activeReposCallback?.([nullthrows(activeRepo)]); + return nullthrows(activeRepo); } function mockNoActiveRepo() { activeRepo = undefined; diff --git a/addons/vscode/extension/blame/blame.ts b/addons/vscode/extension/blame/blame.ts index b7856525cd6e7..7e28956d329d4 100644 --- a/addons/vscode/extension/blame/blame.ts +++ b/addons/vscode/extension/blame/blame.ts @@ -25,7 +25,7 @@ import {getUsername} from 'isl-server/src/analytics/environment'; import {relativeDate} from 'isl/src/relativeDate'; import {LRU} from 'shared/LRU'; import {debounce} from 'shared/debounce'; -import {unwrap} from 'shared/utils'; +import {nullthrows} from 'shared/utils'; import {DecorationRangeBehavior, MarkdownString, Position, Range, window, workspace} from 'vscode'; function areYouTheAuthor(author: string) { @@ -278,7 +278,7 @@ export class InlineBlameProvider implements Disposable { this.ctx.logger.info(`No blame found for path ${path}`); } - const blameLines = unwrap(blame.value); + const blameLines = nullthrows(blame.value); repoCaches.blameCache.set(fileUri, { baseBlameLines: blameLines, @@ -294,7 +294,7 @@ export class InlineBlameProvider implements Disposable { const uri = textEditor.document.uri.fsPath; const repo = this.reposList.repoForPath(uri)?.repo; try { - return {value: await unwrap(repo).blame(this.ctx, uri, baseHash)}; + return {value: await nullthrows(repo).blame(this.ctx, uri, baseHash)}; } catch (err: unknown) { return {error: err as Error}; } @@ -363,7 +363,7 @@ export class InlineBlameProvider implements Disposable { this.updateBlame(this.currentEditor.document); } - const blameLines = unwrap(revisionSet.currentBlameLines); + const blameLines = nullthrows(revisionSet.currentBlameLines); if (line >= blameLines.length) { return undefined; } diff --git a/addons/vscode/extension/islWebviewPanel.ts b/addons/vscode/extension/islWebviewPanel.ts index 5c7de7ebbbab2..93646191d1141 100644 --- a/addons/vscode/extension/islWebviewPanel.ts +++ b/addons/vscode/extension/islWebviewPanel.ts @@ -17,7 +17,7 @@ import {locale, t} from './i18n'; import crypto from 'crypto'; import {onClientConnection} from 'isl-server/src'; import {deserializeFromString, serializeToString} from 'isl/src/serialize'; -import {unwrap} from 'shared/utils'; +import {nullthrows} from 'shared/utils'; import * as vscode from 'vscode'; let islPanelOrView: vscode.WebviewPanel | vscode.WebviewView | undefined = undefined; @@ -48,7 +48,7 @@ function createOrFocusISLWebview( platform, logger, ); - return unwrap(islPanelOrView); + return nullthrows(islPanelOrView); } function getWebviewOptions(