-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set a read-only message from an extension (#185216)
* wip * Allow extensions to provide a readonly message Part of #166971 * Address feedback * Further address feedback * Fix some nits * Add test * Improve tests and respond to feedback * Don't render editor.readOnlyMessage in the settings UI * No need to validate the IMarkdownString --------- Co-authored-by: Benjamin Pasero <[email protected]> Co-authored-by: Alex Dima <[email protected]>
- Loading branch information
1 parent
76cc1fc
commit 1a4e466
Showing
31 changed files
with
349 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
extensions/vscode-api-tests/src/singlefolder-tests/readonlyFileSystem.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as assert from 'assert'; | ||
import * as vscode from 'vscode'; | ||
import { TestFS } from '../memfs'; | ||
import { assertNoRpc, closeAllEditors } from '../utils'; | ||
|
||
suite('vscode API - file system', () => { | ||
|
||
teardown(async function () { | ||
assertNoRpc(); | ||
await closeAllEditors(); | ||
}); | ||
|
||
test('readonly file system - boolean', async function () { | ||
const fs = new TestFS('this-fs', false); | ||
const reg = vscode.workspace.registerFileSystemProvider(fs.scheme, fs, { isReadonly: true }); | ||
let error: any | undefined; | ||
try { | ||
await vscode.workspace.fs.writeFile(vscode.Uri.parse('this-fs:/foo.txt'), Buffer.from('Hello World')); | ||
} catch (e) { | ||
error = e; | ||
} | ||
assert.strictEqual(vscode.workspace.fs.isWritableFileSystem('this-fs'), false); | ||
assert.strictEqual(error instanceof vscode.FileSystemError, true); | ||
const fileError: vscode.FileSystemError = error; | ||
assert.strictEqual(fileError.code, 'NoPermissions'); | ||
reg.dispose(); | ||
}); | ||
|
||
test('readonly file system - markdown', async function () { | ||
const fs = new TestFS('this-fs', false); | ||
const reg = vscode.workspace.registerFileSystemProvider(fs.scheme, fs, { isReadonly: new vscode.MarkdownString('This file is readonly.') }); | ||
let error: any | undefined; | ||
try { | ||
await vscode.workspace.fs.writeFile(vscode.Uri.parse('this-fs:/foo.txt'), Buffer.from('Hello World')); | ||
} catch (e) { | ||
error = e; | ||
} | ||
assert.strictEqual(vscode.workspace.fs.isWritableFileSystem('this-fs'), false); | ||
assert.strictEqual(error instanceof vscode.FileSystemError, true); | ||
const fileError: vscode.FileSystemError = error; | ||
assert.strictEqual(fileError.code, 'NoPermissions'); | ||
reg.dispose(); | ||
}); | ||
|
||
test('writeable file system', async function () { | ||
const fs = new TestFS('this-fs', false); | ||
const reg = vscode.workspace.registerFileSystemProvider(fs.scheme, fs); | ||
let error: any | undefined; | ||
try { | ||
await vscode.workspace.fs.writeFile(vscode.Uri.parse('this-fs:/foo.txt'), Buffer.from('Hello World')); | ||
} catch (e) { | ||
error = e; | ||
} | ||
assert.strictEqual(vscode.workspace.fs.isWritableFileSystem('this-fs'), true); | ||
assert.strictEqual(error, undefined); | ||
reg.dispose(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.