MCPcopy
hub / github.com/VSCodeVim/Vim / setupWorkspace

Function setupWorkspace

test/testUtils.ts:135–184  ·  view source on GitHub ↗
(
  args: {
    config?: Partial<IConfiguration>;
    fileExtension?: string;
    fileContent?: string[];
    forceNewFile?: boolean;
    disableCleanUp?: boolean;
  } = {},
)

Source from the content-addressed store, hash-verified

133}
134
135export async function setupWorkspace(
136 args: {
137 config?: Partial<IConfiguration>;
138 fileExtension?: string;
139 fileContent?: string[];
140 forceNewFile?: boolean;
141 disableCleanUp?: boolean;
142 } = {},
143): Promise<void> {
144 await ExCommandLine.loadHistory(new TestExtensionContext());
145
146 const newFile =
147 vscode.window.activeTextEditor === undefined ||
148 vscode.window.activeTextEditor.document.isUntitled ||
149 vscode.window.visibleTextEditors.length > 1 ||
150 (args.fileExtension &&
151 !vscode.window.activeTextEditor.document.fileName.endsWith(args.fileExtension)) ||
152 args.forceNewFile;
153 const fileContent = (args.fileContent ?? []).join(os.EOL);
154
155 if (newFile) {
156 if (!args.disableCleanUp) await cleanUpWorkspace();
157 const filePath = await createFile({
158 fileExtension: args.fileExtension,
159 contents: fileContent,
160 });
161 const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(filePath));
162 await vscode.window.showTextDocument(doc);
163 }
164
165 const config = new Configuration(args?.config);
166 await reloadConfiguration(config);
167
168 const activeTextEditor = vscode.window.activeTextEditor;
169 assert.ok(activeTextEditor);
170
171 activeTextEditor.options.tabSize = config.tabstop;
172 activeTextEditor.options.insertSpaces = config.expandtab;
173
174 if (!newFile) {
175 assert.ok(
176 await activeTextEditor.edit((builder) => {
177 builder.replace(TextEditor.getDocumentRange(activeTextEditor.document), fileContent);
178 }),
179 'Edit failed',
180 );
181 }
182
183 if (!args.disableCleanUp) ModeHandlerMap.clear();
184}
185
186export async function cleanUpWorkspace(): Promise<void> {
187 await vscode.commands.executeCommand('workbench.action.closeAllEditors');

Callers 15

newTestGenericFunction · 0.90
motion.test.tsFile · 0.90
marks.test.tsFile · 0.90
jumpToNewFileFunction · 0.90
macro.test.tsFile · 0.90
insertLine.test.tsFile · 0.90
modeVisual.test.tsFile · 0.90

Calls 9

cleanUpWorkspaceFunction · 0.85
createFileFunction · 0.85
reloadConfigurationFunction · 0.85
joinMethod · 0.80
editMethod · 0.80
getDocumentRangeMethod · 0.80
loadHistoryMethod · 0.45
replaceMethod · 0.45
clearMethod · 0.45

Tested by 2

jumpToNewFileFunction · 0.72
setupWithBindingsFunction · 0.72