Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
534d10d3
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
534d10d3
编写于
4月 09, 2018
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add FileSystemProvider2 for rapid changes, add readFile/writeFile, simplify delete, #47475
上级
317bf2e6
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
159 addition
and
117 deletion
+159
-117
src/vs/platform/files/common/files.ts
src/vs/platform/files/common/files.ts
+3
-5
src/vs/vscode.proposed.d.ts
src/vs/vscode.proposed.d.ts
+39
-1
src/vs/workbench/api/electron-browser/mainThreadFileSystem.ts
...vs/workbench/api/electron-browser/mainThreadFileSystem.ts
+7
-35
src/vs/workbench/api/node/extHost.api.impl.ts
src/vs/workbench/api/node/extHost.api.impl.ts
+2
-2
src/vs/workbench/api/node/extHost.protocol.ts
src/vs/workbench/api/node/extHost.protocol.ts
+7
-5
src/vs/workbench/api/node/extHostFileSystem.ts
src/vs/workbench/api/node/extHostFileSystem.ts
+86
-26
src/vs/workbench/services/files/electron-browser/remoteFileService.ts
...ench/services/files/electron-browser/remoteFileService.ts
+15
-43
未找到文件。
src/vs/platform/files/common/files.ts
浏览文件 @
534d10d3
...
@@ -12,7 +12,6 @@ import { isLinux } from 'vs/base/common/platform';
...
@@ -12,7 +12,6 @@ import { isLinux } from 'vs/base/common/platform';
import
{
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
Event
}
from
'
vs/base/common/event
'
;
import
{
Event
}
from
'
vs/base/common/event
'
;
import
{
startsWithIgnoreCase
}
from
'
vs/base/common/strings
'
;
import
{
startsWithIgnoreCase
}
from
'
vs/base/common/strings
'
;
import
{
IProgress
}
from
'
vs/platform/progress/common/progress
'
;
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
isEqualOrParent
,
isEqual
}
from
'
vs/base/common/resources
'
;
import
{
isEqualOrParent
,
isEqual
}
from
'
vs/base/common/resources
'
;
import
{
isUndefinedOrNull
}
from
'
vs/base/common/types
'
;
import
{
isUndefinedOrNull
}
from
'
vs/base/common/types
'
;
...
@@ -184,13 +183,12 @@ export interface IFileSystemProvider {
...
@@ -184,13 +183,12 @@ export interface IFileSystemProvider {
//
//
utimes
(
resource
:
URI
,
mtime
:
number
,
atime
:
number
):
TPromise
<
IStat
>
;
utimes
(
resource
:
URI
,
mtime
:
number
,
atime
:
number
):
TPromise
<
IStat
>
;
stat
(
resource
:
URI
):
TPromise
<
IStat
>
;
stat
(
resource
:
URI
):
TPromise
<
IStat
>
;
read
(
resource
:
URI
,
offset
:
number
,
count
:
number
,
progress
:
IProgress
<
Uint8Array
>
):
TPromise
<
number
>
;
read
File
(
resource
:
URI
):
TPromise
<
Uint8Array
>
;
write
(
resource
:
URI
,
content
:
Uint8Array
):
TPromise
<
void
>
;
write
File
(
resource
:
URI
,
content
:
Uint8Array
):
TPromise
<
void
>
;
move
(
from
:
URI
,
to
:
URI
):
TPromise
<
IStat
>
;
move
(
from
:
URI
,
to
:
URI
):
TPromise
<
IStat
>
;
mkdir
(
resource
:
URI
):
TPromise
<
IStat
>
;
mkdir
(
resource
:
URI
):
TPromise
<
IStat
>
;
readdir
(
resource
:
URI
):
TPromise
<
[
URI
,
IStat
][]
>
;
readdir
(
resource
:
URI
):
TPromise
<
[
URI
,
IStat
][]
>
;
rmdir
(
resource
:
URI
):
TPromise
<
void
>
;
delete
(
resource
:
URI
):
TPromise
<
void
>
;
unlink
(
resource
:
URI
):
TPromise
<
void
>
;
}
}
...
...
src/vs/vscode.proposed.d.ts
浏览文件 @
534d10d3
...
@@ -223,8 +223,46 @@ declare module 'vscode' {
...
@@ -223,8 +223,46 @@ declare module 'vscode' {
// create(resource: Uri): Thenable<FileStat>;
// create(resource: Uri): Thenable<FileStat>;
}
}
// todo@joh discover files etc
// todo@joh CancellationToken everywhere
// todo@joh add open/close calls?
export
interface
FileSystemProvider2
{
_version
:
2
;
readonly
onDidChange
?:
Event
<
FileChange
[]
>
;
// more...
//
utimes
(
resource
:
Uri
,
mtime
:
number
,
atime
:
number
):
Thenable
<
FileStat
>
;
stat
(
resource
:
Uri
):
Thenable
<
FileStat
>
;
readFile
(
resource
:
Uri
,
token
:
CancellationToken
):
Thenable
<
Uint8Array
>
;
writeFile
(
resource
:
Uri
,
content
:
Uint8Array
,
token
:
CancellationToken
):
Thenable
<
void
>
;
// todo@remote
// Thenable<FileStat>
move
(
resource
:
Uri
,
target
:
Uri
):
Thenable
<
FileStat
>
;
// todo@remote
// helps with performance bigly
// copy?(from: Uri, to: Uri): Thenable<void>;
readdir
(
resource
:
Uri
):
Thenable
<
[
Uri
,
FileStat
][]
>
;
// todo@remote
// ? useTrash, expose trash
delete
(
resource
:
Uri
,
options
:
{
recursive
?:
boolean
;
}):
Thenable
<
void
>
;
// todo@remote
create
(
resource
:
Uri
,
options
:
{
type
:
FileType
}):
Thenable
<
FileStat
>
;
}
export
namespace
workspace
{
export
namespace
workspace
{
export
function
registerFileSystemProvider
(
scheme
:
string
,
provider
:
FileSystemProvider
):
Disposable
;
export
function
registerFileSystemProvider
(
scheme
:
string
,
provider
:
FileSystemProvider
,
newProvider
?:
FileSystemProvider2
):
Disposable
;
}
}
//#endregion
//#endregion
...
...
src/vs/workbench/api/electron-browser/mainThreadFileSystem.ts
浏览文件 @
534d10d3
...
@@ -11,7 +11,6 @@ import { IFileService, IFileSystemProvider, IStat, IFileChange } from 'vs/platfo
...
@@ -11,7 +11,6 @@ import { IFileService, IFileSystemProvider, IStat, IFileChange } from 'vs/platfo
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
Event
,
Emitter
}
from
'
vs/base/common/event
'
;
import
{
Event
,
Emitter
}
from
'
vs/base/common/event
'
;
import
{
extHostNamedCustomer
}
from
'
vs/workbench/api/electron-browser/extHostCustomers
'
;
import
{
extHostNamedCustomer
}
from
'
vs/workbench/api/electron-browser/extHostCustomers
'
;
import
{
IProgress
}
from
'
vs/platform/progress/common/progress
'
;
import
{
ISearchResultProvider
,
ISearchQuery
,
ISearchComplete
,
ISearchProgressItem
,
QueryType
,
IFileMatch
,
ISearchService
,
ILineMatch
}
from
'
vs/platform/search/common/search
'
;
import
{
ISearchResultProvider
,
ISearchQuery
,
ISearchComplete
,
ISearchProgressItem
,
QueryType
,
IFileMatch
,
ISearchService
,
ILineMatch
}
from
'
vs/platform/search/common/search
'
;
import
{
values
}
from
'
vs/base/common/map
'
;
import
{
values
}
from
'
vs/base/common/map
'
;
import
{
isFalsyOrEmpty
}
from
'
vs/base/common/arrays
'
;
import
{
isFalsyOrEmpty
}
from
'
vs/base/common/arrays
'
;
...
@@ -55,11 +54,6 @@ export class MainThreadFileSystem implements MainThreadFileSystemShape {
...
@@ -55,11 +54,6 @@ export class MainThreadFileSystem implements MainThreadFileSystemShape {
$onFileSystemChange
(
handle
:
number
,
changes
:
IFileChangeDto
[]):
void
{
$onFileSystemChange
(
handle
:
number
,
changes
:
IFileChangeDto
[]):
void
{
this
.
_fileProvider
.
get
(
handle
).
$onFileSystemChange
(
changes
);
this
.
_fileProvider
.
get
(
handle
).
$onFileSystemChange
(
changes
);
}
}
$reportFileChunk
(
handle
:
number
,
session
:
number
,
base64Chunk
:
string
):
void
{
this
.
_fileProvider
.
get
(
handle
).
reportFileChunk
(
session
,
base64Chunk
);
}
// --- search
// --- search
$handleFindMatch
(
handle
:
number
,
session
,
data
:
UriComponents
|
[
UriComponents
,
ILineMatch
]):
void
{
$handleFindMatch
(
handle
:
number
,
session
,
data
:
UriComponents
|
[
UriComponents
,
ILineMatch
]):
void
{
...
@@ -67,23 +61,10 @@ export class MainThreadFileSystem implements MainThreadFileSystemShape {
...
@@ -67,23 +61,10 @@ export class MainThreadFileSystem implements MainThreadFileSystemShape {
}
}
}
}
class
FileReadOperation
{
private
static
_idPool
=
0
;
constructor
(
readonly
progress
:
IProgress
<
Uint8Array
>
,
readonly
id
:
number
=
++
FileReadOperation
.
_idPool
)
{
//
}
}
class
RemoteFileSystemProvider
implements
IFileSystemProvider
{
class
RemoteFileSystemProvider
implements
IFileSystemProvider
{
private
readonly
_onDidChange
=
new
Emitter
<
IFileChange
[]
>
();
private
readonly
_onDidChange
=
new
Emitter
<
IFileChange
[]
>
();
private
readonly
_registrations
:
IDisposable
[];
private
readonly
_registrations
:
IDisposable
[];
private
readonly
_reads
=
new
Map
<
number
,
FileReadOperation
>
();
readonly
onDidChange
:
Event
<
IFileChange
[]
>
=
this
.
_onDidChange
.
event
;
readonly
onDidChange
:
Event
<
IFileChange
[]
>
=
this
.
_onDidChange
.
event
;
...
@@ -118,25 +99,19 @@ class RemoteFileSystemProvider implements IFileSystemProvider {
...
@@ -118,25 +99,19 @@ class RemoteFileSystemProvider implements IFileSystemProvider {
stat
(
resource
:
URI
):
TPromise
<
IStat
,
any
>
{
stat
(
resource
:
URI
):
TPromise
<
IStat
,
any
>
{
return
this
.
_proxy
.
$stat
(
this
.
_handle
,
resource
);
return
this
.
_proxy
.
$stat
(
this
.
_handle
,
resource
);
}
}
read
(
resource
:
URI
,
offset
:
number
,
count
:
number
,
progress
:
IProgress
<
Uint8Array
>
):
TPromise
<
number
,
any
>
{
readFile
(
resource
:
URI
):
TPromise
<
Uint8Array
,
any
>
{
const
read
=
new
FileReadOperation
(
progress
);
return
this
.
_proxy
.
$readFile
(
this
.
_handle
,
resource
).
then
(
encoded
=>
{
this
.
_reads
.
set
(
read
.
id
,
read
);
return
Buffer
.
from
(
encoded
,
'
base64
'
);
return
this
.
_proxy
.
$read
(
this
.
_handle
,
read
.
id
,
offset
,
count
,
resource
).
then
(
value
=>
{
this
.
_reads
.
delete
(
read
.
id
);
return
value
;
});
});
}
}
reportFileChunk
(
session
:
number
,
encodedChunk
:
string
):
void
{
writeFile
(
resource
:
URI
,
content
:
Uint8Array
):
TPromise
<
void
,
any
>
{
this
.
_reads
.
get
(
session
).
progress
.
report
(
Buffer
.
from
(
encodedChunk
,
'
base64
'
));
}
write
(
resource
:
URI
,
content
:
Uint8Array
):
TPromise
<
void
,
any
>
{
let
encoded
=
Buffer
.
isBuffer
(
content
)
let
encoded
=
Buffer
.
isBuffer
(
content
)
?
content
.
toString
(
'
base64
'
)
?
content
.
toString
(
'
base64
'
)
:
Buffer
.
from
(
content
.
buffer
,
content
.
byteOffset
,
content
.
byteLength
).
toString
(
'
base64
'
);
:
Buffer
.
from
(
content
.
buffer
,
content
.
byteOffset
,
content
.
byteLength
).
toString
(
'
base64
'
);
return
this
.
_proxy
.
$write
(
this
.
_handle
,
resource
,
encoded
);
return
this
.
_proxy
.
$write
File
(
this
.
_handle
,
resource
,
encoded
);
}
}
unlink
(
resource
:
URI
):
TPromise
<
void
,
any
>
{
delete
(
resource
:
URI
):
TPromise
<
void
,
any
>
{
return
this
.
_proxy
.
$
unlink
(
this
.
_handle
,
resource
);
return
this
.
_proxy
.
$
delete
(
this
.
_handle
,
resource
);
}
}
move
(
resource
:
URI
,
target
:
URI
):
TPromise
<
IStat
,
any
>
{
move
(
resource
:
URI
,
target
:
URI
):
TPromise
<
IStat
,
any
>
{
return
this
.
_proxy
.
$move
(
this
.
_handle
,
resource
,
target
);
return
this
.
_proxy
.
$move
(
this
.
_handle
,
resource
,
target
);
...
@@ -149,9 +124,6 @@ class RemoteFileSystemProvider implements IFileSystemProvider {
...
@@ -149,9 +124,6 @@ class RemoteFileSystemProvider implements IFileSystemProvider {
return
data
.
map
(
tuple
=>
<
[
URI
,
IStat
]
>
[
URI
.
revive
(
tuple
[
0
]),
tuple
[
1
]]);
return
data
.
map
(
tuple
=>
<
[
URI
,
IStat
]
>
[
URI
.
revive
(
tuple
[
0
]),
tuple
[
1
]]);
});
});
}
}
rmdir
(
resource
:
URI
):
TPromise
<
void
,
any
>
{
return
this
.
_proxy
.
$rmdir
(
this
.
_handle
,
resource
);
}
}
}
class
SearchOperation
{
class
SearchOperation
{
...
...
src/vs/workbench/api/node/extHost.api.impl.ts
浏览文件 @
534d10d3
...
@@ -538,8 +538,8 @@ export function createApiFactory(
...
@@ -538,8 +538,8 @@ export function createApiFactory(
onDidEndTask
:
(
listeners
,
thisArgs
?,
disposables
?)
=>
{
onDidEndTask
:
(
listeners
,
thisArgs
?,
disposables
?)
=>
{
return
extHostTask
.
onDidEndTask
(
listeners
,
thisArgs
,
disposables
);
return
extHostTask
.
onDidEndTask
(
listeners
,
thisArgs
,
disposables
);
},
},
registerFileSystemProvider
:
proposedApiFunction
(
extension
,
(
scheme
,
provider
)
=>
{
registerFileSystemProvider
:
proposedApiFunction
(
extension
,
(
scheme
,
provider
,
newProvider
?
)
=>
{
return
extHostFileSystem
.
registerFileSystemProvider
(
scheme
,
provider
);
return
extHostFileSystem
.
registerFileSystemProvider
(
scheme
,
provider
,
newProvider
);
}),
}),
registerSearchProvider
:
proposedApiFunction
(
extension
,
(
scheme
,
provider
)
=>
{
registerSearchProvider
:
proposedApiFunction
(
extension
,
(
scheme
,
provider
)
=>
{
return
extHostFileSystem
.
registerSearchProvider
(
scheme
,
provider
);
return
extHostFileSystem
.
registerSearchProvider
(
scheme
,
provider
);
...
...
src/vs/workbench/api/node/extHost.protocol.ts
浏览文件 @
534d10d3
...
@@ -387,7 +387,6 @@ export interface MainThreadFileSystemShape extends IDisposable {
...
@@ -387,7 +387,6 @@ export interface MainThreadFileSystemShape extends IDisposable {
$unregisterProvider
(
handle
:
number
):
void
;
$unregisterProvider
(
handle
:
number
):
void
;
$onFileSystemChange
(
handle
:
number
,
resource
:
IFileChangeDto
[]):
void
;
$onFileSystemChange
(
handle
:
number
,
resource
:
IFileChangeDto
[]):
void
;
$reportFileChunk
(
handle
:
number
,
session
:
number
,
base64Encoded
:
string
|
null
):
void
;
$handleFindMatch
(
handle
:
number
,
session
,
data
:
UriComponents
|
[
UriComponents
,
ILineMatch
]):
void
;
$handleFindMatch
(
handle
:
number
,
session
,
data
:
UriComponents
|
[
UriComponents
,
ILineMatch
]):
void
;
}
}
...
@@ -568,13 +567,16 @@ export interface ExtHostWorkspaceShape {
...
@@ -568,13 +567,16 @@ export interface ExtHostWorkspaceShape {
export
interface
ExtHostFileSystemShape
{
export
interface
ExtHostFileSystemShape
{
$utimes
(
handle
:
number
,
resource
:
UriComponents
,
mtime
:
number
,
atime
:
number
):
TPromise
<
IStat
>
;
$utimes
(
handle
:
number
,
resource
:
UriComponents
,
mtime
:
number
,
atime
:
number
):
TPromise
<
IStat
>
;
$stat
(
handle
:
number
,
resource
:
UriComponents
):
TPromise
<
IStat
>
;
$stat
(
handle
:
number
,
resource
:
UriComponents
):
TPromise
<
IStat
>
;
$read
(
handle
:
number
,
session
:
number
,
offset
:
number
,
count
:
number
,
resource
:
UriComponents
):
TPromise
<
number
>
;
$write
(
handle
:
number
,
resource
:
UriComponents
,
base64Encoded
:
string
):
TPromise
<
void
>
;
$readFile
(
handle
:
number
,
resource
:
UriComponents
):
TPromise
<
string
>
;
$unlink
(
handle
:
number
,
resource
:
UriComponents
):
TPromise
<
void
>
;
$writeFile
(
handle
:
number
,
resource
:
UriComponents
,
base64Encoded
:
string
):
TPromise
<
void
>
;
$move
(
handle
:
number
,
resource
:
UriComponents
,
target
:
UriComponents
):
TPromise
<
IStat
>
;
$move
(
handle
:
number
,
resource
:
UriComponents
,
target
:
UriComponents
):
TPromise
<
IStat
>
;
$mkdir
(
handle
:
number
,
resource
:
UriComponents
):
TPromise
<
IStat
>
;
$mkdir
(
handle
:
number
,
resource
:
UriComponents
):
TPromise
<
IStat
>
;
$readdir
(
handle
:
number
,
resource
:
UriComponents
):
TPromise
<
[
UriComponents
,
IStat
][]
>
;
$readdir
(
handle
:
number
,
resource
:
UriComponents
):
TPromise
<
[
UriComponents
,
IStat
][]
>
;
$rmdir
(
handle
:
number
,
resource
:
UriComponents
):
TPromise
<
void
>
;
$delete
(
handle
:
number
,
resource
:
UriComponents
):
TPromise
<
void
>
;
$provideFileSearchResults
(
handle
:
number
,
session
:
number
,
query
:
string
):
TPromise
<
void
>
;
$provideFileSearchResults
(
handle
:
number
,
session
:
number
,
query
:
string
):
TPromise
<
void
>
;
$provideTextSearchResults
(
handle
:
number
,
session
:
number
,
pattern
:
IPatternInfo
,
options
:
{
includes
:
string
[],
excludes
:
string
[]
}):
TPromise
<
void
>
;
$provideTextSearchResults
(
handle
:
number
,
session
:
number
,
pattern
:
IPatternInfo
,
options
:
{
includes
:
string
[],
excludes
:
string
[]
}):
TPromise
<
void
>
;
}
}
...
...
src/vs/workbench/api/node/extHostFileSystem.ts
浏览文件 @
534d10d3
...
@@ -13,9 +13,8 @@ import { IDisposable } from 'vs/base/common/lifecycle';
...
@@ -13,9 +13,8 @@ import { IDisposable } from 'vs/base/common/lifecycle';
import
{
asWinJsPromise
}
from
'
vs/base/common/async
'
;
import
{
asWinJsPromise
}
from
'
vs/base/common/async
'
;
import
{
IPatternInfo
}
from
'
vs/platform/search/common/search
'
;
import
{
IPatternInfo
}
from
'
vs/platform/search/common/search
'
;
import
{
values
}
from
'
vs/base/common/map
'
;
import
{
values
}
from
'
vs/base/common/map
'
;
import
{
Range
}
from
'
vs/workbench/api/node/extHostTypes
'
;
import
{
Range
,
FileType
}
from
'
vs/workbench/api/node/extHostTypes
'
;
import
{
ExtHostLanguageFeatures
}
from
'
vs/workbench/api/node/extHostLanguageFeatures
'
;
import
{
ExtHostLanguageFeatures
}
from
'
vs/workbench/api/node/extHostLanguageFeatures
'
;
import
{
IProgress
}
from
'
vs/platform/progress/common/progress
'
;
class
FsLinkProvider
implements
vscode
.
DocumentLinkProvider
{
class
FsLinkProvider
implements
vscode
.
DocumentLinkProvider
{
...
@@ -56,10 +55,70 @@ class FsLinkProvider implements vscode.DocumentLinkProvider {
...
@@ -56,10 +55,70 @@ class FsLinkProvider implements vscode.DocumentLinkProvider {
}
}
}
}
class
FileSystemProviderShim
implements
vscode
.
FileSystemProvider2
{
_version
:
2
;
onDidChange
?:
vscode
.
Event
<
vscode
.
FileChange
[]
>
;
constructor
(
private
readonly
_delegate
:
vscode
.
FileSystemProvider
)
{
this
.
onDidChange
=
this
.
_delegate
.
onDidChange
;
}
utimes
(
resource
:
vscode
.
Uri
,
mtime
:
number
,
atime
:
number
):
Thenable
<
vscode
.
FileStat
>
{
return
this
.
_delegate
.
utimes
(
resource
,
mtime
,
atime
);
}
stat
(
resource
:
vscode
.
Uri
):
Thenable
<
vscode
.
FileStat
>
{
return
this
.
_delegate
.
stat
(
resource
);
}
move
(
resource
:
vscode
.
Uri
,
target
:
vscode
.
Uri
):
Thenable
<
vscode
.
FileStat
>
{
return
this
.
move
(
resource
,
target
);
}
readdir
(
resource
:
vscode
.
Uri
):
Thenable
<
[
vscode
.
Uri
,
vscode
.
FileStat
][]
>
{
return
this
.
_delegate
.
readdir
(
resource
);
}
// --- delete/create file or folder
delete
(
resource
:
vscode
.
Uri
,
options
:
{
recursive
:
boolean
;
}):
Thenable
<
void
>
{
return
this
.
stat
(
resource
).
then
(
stat
=>
{
if
(
stat
.
type
===
FileType
.
Dir
)
{
return
this
.
_delegate
.
rmdir
(
resource
);
}
else
{
return
this
.
_delegate
.
unlink
(
resource
);
}
});
}
create
(
resource
:
vscode
.
Uri
,
options
:
{
type
:
vscode
.
FileType
;
}):
Thenable
<
vscode
.
FileStat
>
{
if
(
options
.
type
===
FileType
.
Dir
)
{
return
this
.
_delegate
.
mkdir
(
resource
);
}
else
{
return
this
.
_delegate
.
write
(
resource
,
Buffer
.
from
([])).
then
(()
=>
this
.
_delegate
.
stat
(
resource
));
}
}
// --- read/write
readFile
(
resource
:
vscode
.
Uri
):
Thenable
<
Uint8Array
>
{
let
chunks
:
Buffer
[]
=
[];
return
this
.
_delegate
.
read
(
resource
,
0
,
-
1
,
{
report
(
data
)
{
chunks
.
push
(
Buffer
.
from
(
data
));
}
}).
then
(()
=>
{
return
Buffer
.
concat
(
chunks
);
});
}
writeFile
(
resource
:
vscode
.
Uri
,
content
:
Uint8Array
):
Thenable
<
void
>
{
return
this
.
_delegate
.
write
(
resource
,
content
);
}
}
export
class
ExtHostFileSystem
implements
ExtHostFileSystemShape
{
export
class
ExtHostFileSystem
implements
ExtHostFileSystemShape
{
private
readonly
_proxy
:
MainThreadFileSystemShape
;
private
readonly
_proxy
:
MainThreadFileSystemShape
;
private
readonly
_fsProvider
=
new
Map
<
number
,
vscode
.
FileSystemProvider
>
();
private
readonly
_fsProvider
=
new
Map
<
number
,
vscode
.
FileSystemProvider
2
>
();
private
readonly
_searchProvider
=
new
Map
<
number
,
vscode
.
SearchProvider
>
();
private
readonly
_searchProvider
=
new
Map
<
number
,
vscode
.
SearchProvider
>
();
private
readonly
_linkProvider
=
new
FsLinkProvider
();
private
readonly
_linkProvider
=
new
FsLinkProvider
();
...
@@ -70,7 +129,15 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape {
...
@@ -70,7 +129,15 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape {
extHostLanguageFeatures
.
registerDocumentLinkProvider
(
'
*
'
,
this
.
_linkProvider
);
extHostLanguageFeatures
.
registerDocumentLinkProvider
(
'
*
'
,
this
.
_linkProvider
);
}
}
registerFileSystemProvider
(
scheme
:
string
,
provider
:
vscode
.
FileSystemProvider
)
{
registerFileSystemProvider
(
scheme
:
string
,
provider
:
vscode
.
FileSystemProvider
,
newProvider
:
vscode
.
FileSystemProvider2
)
{
if
(
newProvider
&&
newProvider
.
_version
===
2
)
{
return
this
.
_doRegisterFileSystemProvider
(
scheme
,
newProvider
);
}
else
{
return
this
.
_doRegisterFileSystemProvider
(
scheme
,
new
FileSystemProviderShim
(
provider
));
}
}
private
_doRegisterFileSystemProvider
(
scheme
:
string
,
provider
:
vscode
.
FileSystemProvider2
)
{
const
handle
=
this
.
_handlePool
++
;
const
handle
=
this
.
_handlePool
++
;
this
.
_linkProvider
.
add
(
scheme
);
this
.
_linkProvider
.
add
(
scheme
);
this
.
_fsProvider
.
set
(
handle
,
provider
);
this
.
_fsProvider
.
set
(
handle
,
provider
);
...
@@ -109,36 +176,29 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape {
...
@@ -109,36 +176,29 @@ export class ExtHostFileSystem implements ExtHostFileSystemShape {
$stat
(
handle
:
number
,
resource
:
UriComponents
):
TPromise
<
IStat
,
any
>
{
$stat
(
handle
:
number
,
resource
:
UriComponents
):
TPromise
<
IStat
,
any
>
{
return
asWinJsPromise
(
token
=>
this
.
_fsProvider
.
get
(
handle
).
stat
(
URI
.
revive
(
resource
)));
return
asWinJsPromise
(
token
=>
this
.
_fsProvider
.
get
(
handle
).
stat
(
URI
.
revive
(
resource
)));
}
}
$read
(
handle
:
number
,
session
:
number
,
offset
:
number
,
count
:
number
,
resource
:
UriComponents
):
TPromise
<
number
>
{
$readdir
(
handle
:
number
,
resource
:
UriComponents
):
TPromise
<
[
UriComponents
,
IStat
][],
any
>
{
const
progress
:
IProgress
<
Uint8Array
>
=
{
return
asWinJsPromise
(
token
=>
this
.
_fsProvider
.
get
(
handle
).
readdir
(
URI
.
revive
(
resource
)));
report
:
chunk
=>
{
let
base64Chunk
=
Buffer
.
isBuffer
(
chunk
)
?
chunk
.
toString
(
'
base64
'
)
:
Buffer
.
from
(
chunk
.
buffer
,
chunk
.
byteOffset
,
chunk
.
byteLength
).
toString
(
'
base64
'
);
this
.
_proxy
.
$reportFileChunk
(
handle
,
session
,
base64Chunk
);
}
};
return
asWinJsPromise
(
token
=>
this
.
_fsProvider
.
get
(
handle
).
read
(
URI
.
revive
(
resource
),
offset
,
count
,
progress
));
}
}
$write
(
handle
:
number
,
resource
:
UriComponents
,
base64Content
:
string
):
TPromise
<
void
,
any
>
{
$readFile
(
handle
:
number
,
resource
:
UriComponents
):
TPromise
<
string
>
{
return
asWinJsPromise
(
token
=>
this
.
_fsProvider
.
get
(
handle
).
write
(
URI
.
revive
(
resource
),
Buffer
.
from
(
base64Content
,
'
base64
'
)));
return
asWinJsPromise
(
token
=>
{
return
this
.
_fsProvider
.
get
(
handle
).
readFile
(
URI
.
revive
(
resource
),
token
);
}).
then
(
data
=>
{
return
Buffer
.
isBuffer
(
data
)
?
data
.
toString
(
'
base64
'
)
:
Buffer
.
from
(
data
.
buffer
,
data
.
byteOffset
,
data
.
byteLength
).
toString
(
'
base64
'
);
});
}
}
$unlink
(
handle
:
number
,
resource
:
UriComponents
):
TPromise
<
void
,
any
>
{
$writeFile
(
handle
:
number
,
resource
:
UriComponents
,
base64Content
:
string
):
TPromise
<
void
,
any
>
{
return
asWinJsPromise
(
token
=>
this
.
_fsProvider
.
get
(
handle
).
unlink
(
URI
.
revive
(
resource
)));
return
asWinJsPromise
(
token
=>
this
.
_fsProvider
.
get
(
handle
).
writeFile
(
URI
.
revive
(
resource
),
Buffer
.
from
(
base64Content
,
'
base64
'
),
token
));
}
$delete
(
handle
:
number
,
resource
:
UriComponents
):
TPromise
<
void
,
any
>
{
return
asWinJsPromise
(
token
=>
this
.
_fsProvider
.
get
(
handle
).
delete
(
URI
.
revive
(
resource
),
{
recursive
:
true
}));
}
}
$move
(
handle
:
number
,
resource
:
UriComponents
,
target
:
UriComponents
):
TPromise
<
IStat
,
any
>
{
$move
(
handle
:
number
,
resource
:
UriComponents
,
target
:
UriComponents
):
TPromise
<
IStat
,
any
>
{
return
asWinJsPromise
(
token
=>
this
.
_fsProvider
.
get
(
handle
).
move
(
URI
.
revive
(
resource
),
URI
.
revive
(
target
)));
return
asWinJsPromise
(
token
=>
this
.
_fsProvider
.
get
(
handle
).
move
(
URI
.
revive
(
resource
),
URI
.
revive
(
target
)));
}
}
$mkdir
(
handle
:
number
,
resource
:
UriComponents
):
TPromise
<
IStat
,
any
>
{
$mkdir
(
handle
:
number
,
resource
:
UriComponents
):
TPromise
<
IStat
,
any
>
{
return
asWinJsPromise
(
token
=>
this
.
_fsProvider
.
get
(
handle
).
mkdir
(
URI
.
revive
(
resource
)));
return
asWinJsPromise
(
token
=>
this
.
_fsProvider
.
get
(
handle
).
create
(
URI
.
revive
(
resource
),
{
type
:
FileType
.
Dir
}));
}
$readdir
(
handle
:
number
,
resource
:
UriComponents
):
TPromise
<
[
UriComponents
,
IStat
][],
any
>
{
return
asWinJsPromise
(
token
=>
this
.
_fsProvider
.
get
(
handle
).
readdir
(
URI
.
revive
(
resource
)));
}
$rmdir
(
handle
:
number
,
resource
:
UriComponents
):
TPromise
<
void
,
any
>
{
return
asWinJsPromise
(
token
=>
this
.
_fsProvider
.
get
(
handle
).
rmdir
(
URI
.
revive
(
resource
)));
}
}
$provideFileSearchResults
(
handle
:
number
,
session
:
number
,
query
:
string
):
TPromise
<
void
>
{
$provideFileSearchResults
(
handle
:
number
,
session
:
number
,
query
:
string
):
TPromise
<
void
>
{
const
provider
=
this
.
_searchProvider
.
get
(
handle
);
const
provider
=
this
.
_searchProvider
.
get
(
handle
);
if
(
!
provider
.
provideFileSearchResults
)
{
if
(
!
provider
.
provideFileSearchResults
)
{
...
...
src/vs/workbench/services/files/electron-browser/remoteFileService.ts
浏览文件 @
534d10d3
...
@@ -12,7 +12,6 @@ import { posix } from 'path';
...
@@ -12,7 +12,6 @@ import { posix } from 'path';
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
isFalsyOrEmpty
,
distinct
}
from
'
vs/base/common/arrays
'
;
import
{
isFalsyOrEmpty
,
distinct
}
from
'
vs/base/common/arrays
'
;
import
{
Schemas
}
from
'
vs/base/common/network
'
;
import
{
Schemas
}
from
'
vs/base/common/network
'
;
import
{
Progress
}
from
'
vs/platform/progress/common/progress
'
;
import
{
decodeStream
,
encode
,
UTF8
,
UTF8_with_bom
,
detectEncodingFromBuffer
,
maxEncodingDetectionBufferLen
}
from
'
vs/base/node/encoding
'
;
import
{
decodeStream
,
encode
,
UTF8
,
UTF8_with_bom
,
detectEncodingFromBuffer
,
maxEncodingDetectionBufferLen
}
from
'
vs/base/node/encoding
'
;
import
{
TernarySearchTree
}
from
'
vs/base/common/map
'
;
import
{
TernarySearchTree
}
from
'
vs/base/common/map
'
;
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
...
@@ -213,7 +212,7 @@ export class RemoteFileService extends FileService {
...
@@ -213,7 +212,7 @@ export class RemoteFileService extends FileService {
if
(
resource
.
scheme
===
Schemas
.
file
)
{
if
(
resource
.
scheme
===
Schemas
.
file
)
{
return
super
.
resolveContent
(
resource
,
options
);
return
super
.
resolveContent
(
resource
,
options
);
}
else
{
}
else
{
return
this
.
_
doResolveContent
(
resource
,
options
).
then
(
RemoteFileService
.
_asContent
);
return
this
.
_
readFile
(
resource
,
options
).
then
(
RemoteFileService
.
_asContent
);
}
}
}
}
...
@@ -221,11 +220,11 @@ export class RemoteFileService extends FileService {
...
@@ -221,11 +220,11 @@ export class RemoteFileService extends FileService {
if
(
resource
.
scheme
===
Schemas
.
file
)
{
if
(
resource
.
scheme
===
Schemas
.
file
)
{
return
super
.
resolveStreamContent
(
resource
,
options
);
return
super
.
resolveStreamContent
(
resource
,
options
);
}
else
{
}
else
{
return
this
.
_
doResolveContent
(
resource
,
options
);
return
this
.
_
readFile
(
resource
,
options
);
}
}
}
}
private
_
doResolveContent
(
resource
:
URI
,
options
:
IResolveContentOptions
=
Object
.
create
(
null
)):
TPromise
<
IStreamContent
>
{
private
_
readFile
(
resource
:
URI
,
options
:
IResolveContentOptions
=
Object
.
create
(
null
)):
TPromise
<
IStreamContent
>
{
return
this
.
_withProvider
(
resource
).
then
(
provider
=>
{
return
this
.
_withProvider
(
resource
).
then
(
provider
=>
{
return
this
.
resolveFile
(
resource
).
then
(
fileStat
=>
{
return
this
.
resolveFile
(
resource
).
then
(
fileStat
=>
{
...
@@ -249,15 +248,11 @@ export class RemoteFileService extends FileService {
...
@@ -249,15 +248,11 @@ export class RemoteFileService extends FileService {
const
guessEncoding
=
options
.
autoGuessEncoding
;
const
guessEncoding
=
options
.
autoGuessEncoding
;
const
count
=
maxEncodingDetectionBufferLen
(
options
);
const
count
=
maxEncodingDetectionBufferLen
(
options
);
const
chunks
:
Buffer
[]
=
[];
let
buffer
:
Buffer
;
return
provider
.
read
(
resource
,
0
,
count
,
new
Progress
<
Buffer
>
(
chunk
=>
chunks
.
push
(
chunk
))
).
then
(
bytesRead
=>
{
return
detectEncodingFromBuffer
({
bytesRead
,
buffer
:
Buffer
.
concat
(
chunks
)
},
guessEncoding
);
return
provider
.
readFile
(
resource
).
then
(
data
=>
{
buffer
=
Buffer
.
from
(
data
);
return
detectEncodingFromBuffer
({
bytesRead
:
Math
.
min
(
count
,
buffer
.
length
),
buffer
},
guessEncoding
);
}).
then
(
detected
=>
{
}).
then
(
detected
=>
{
if
(
options
.
acceptTextOnly
&&
detected
.
seemsBinary
)
{
if
(
options
.
acceptTextOnly
&&
detected
.
seemsBinary
)
{
return
TPromise
.
wrapError
<
IStreamContent
>
(
new
FileOperationError
(
return
TPromise
.
wrapError
<
IStreamContent
>
(
new
FileOperationError
(
...
@@ -289,27 +284,7 @@ export class RemoteFileService extends FileService {
...
@@ -289,27 +284,7 @@ export class RemoteFileService extends FileService {
// const encoding = this.getEncoding(resource);
// const encoding = this.getEncoding(resource);
const
stream
=
decodeStream
(
preferredEncoding
);
const
stream
=
decodeStream
(
preferredEncoding
);
stream
.
end
(
buffer
);
// start with what we have already read
// and have a new stream to read the rest
let
offset
=
0
;
for
(
const
chunk
of
chunks
)
{
stream
.
write
(
chunk
);
offset
+=
chunk
.
length
;
}
if
(
offset
<
count
)
{
// we didn't read enough the first time which means
// that we are done
stream
.
end
();
}
else
{
// there is more to read
provider
.
read
(
resource
,
offset
,
-
1
,
new
Progress
<
Buffer
>
(
chunk
=>
stream
.
write
(
chunk
))).
then
(()
=>
{
stream
.
end
();
},
err
=>
{
stream
.
emit
(
'
error
'
,
err
);
stream
.
end
();
});
}
return
{
return
{
encoding
:
preferredEncoding
,
encoding
:
preferredEncoding
,
...
@@ -340,7 +315,7 @@ export class RemoteFileService extends FileService {
...
@@ -340,7 +315,7 @@ export class RemoteFileService extends FileService {
if
(
exists
&&
options
&&
!
options
.
overwrite
)
{
if
(
exists
&&
options
&&
!
options
.
overwrite
)
{
return
TPromise
.
wrapError
(
new
FileOperationError
(
'
EEXIST
'
,
FileOperationResult
.
FILE_MODIFIED_SINCE
,
options
));
return
TPromise
.
wrapError
(
new
FileOperationError
(
'
EEXIST
'
,
FileOperationResult
.
FILE_MODIFIED_SINCE
,
options
));
}
}
return
this
.
_
doUpdateContent
(
provider
,
resource
,
content
||
''
,
{});
return
this
.
_
writeFile
(
provider
,
resource
,
content
||
''
,
{});
}).
then
(
fileStat
=>
{
}).
then
(
fileStat
=>
{
this
.
_onAfterOperation
.
fire
(
new
FileOperationEvent
(
resource
,
FileOperation
.
CREATE
,
fileStat
));
this
.
_onAfterOperation
.
fire
(
new
FileOperationEvent
(
resource
,
FileOperation
.
CREATE
,
fileStat
));
return
fileStat
;
return
fileStat
;
...
@@ -354,15 +329,15 @@ export class RemoteFileService extends FileService {
...
@@ -354,15 +329,15 @@ export class RemoteFileService extends FileService {
return
super
.
updateContent
(
resource
,
value
,
options
);
return
super
.
updateContent
(
resource
,
value
,
options
);
}
else
{
}
else
{
return
this
.
_withProvider
(
resource
).
then
(
provider
=>
{
return
this
.
_withProvider
(
resource
).
then
(
provider
=>
{
return
this
.
_
doUpdateContent
(
provider
,
resource
,
value
,
options
||
{});
return
this
.
_
writeFile
(
provider
,
resource
,
value
,
options
||
{});
});
});
}
}
}
}
private
_
doUpdateContent
(
provider
:
IFileSystemProvider
,
resource
:
URI
,
content
:
string
|
ITextSnapshot
,
options
:
IUpdateContentOptions
):
TPromise
<
IFileStat
>
{
private
_
writeFile
(
provider
:
IFileSystemProvider
,
resource
:
URI
,
content
:
string
|
ITextSnapshot
,
options
:
IUpdateContentOptions
):
TPromise
<
IFileStat
>
{
const
encoding
=
this
.
getEncoding
(
resource
,
options
.
encoding
);
const
encoding
=
this
.
getEncoding
(
resource
,
options
.
encoding
);
// TODO@Joh support streaming API for remote file system writes
// TODO@Joh support streaming API for remote file system writes
return
provider
.
write
(
resource
,
encode
(
typeof
content
===
'
string
'
?
content
:
snapshotToString
(
content
),
encoding
)).
then
(()
=>
{
return
provider
.
write
File
(
resource
,
encode
(
typeof
content
===
'
string
'
?
content
:
snapshotToString
(
content
),
encoding
)).
then
(()
=>
{
return
this
.
resolveFile
(
resource
);
return
this
.
resolveFile
(
resource
);
});
});
}
}
...
@@ -390,9 +365,7 @@ export class RemoteFileService extends FileService {
...
@@ -390,9 +365,7 @@ export class RemoteFileService extends FileService {
return
super
.
del
(
resource
,
useTrash
);
return
super
.
del
(
resource
,
useTrash
);
}
else
{
}
else
{
return
this
.
_withProvider
(
resource
).
then
(
provider
=>
{
return
this
.
_withProvider
(
resource
).
then
(
provider
=>
{
return
provider
.
stat
(
resource
).
then
(
stat
=>
{
return
provider
.
delete
(
resource
).
then
(()
=>
{
return
stat
.
type
===
FileType
.
Dir
?
provider
.
rmdir
(
resource
)
:
provider
.
unlink
(
resource
);
}).
then
(()
=>
{
this
.
_onAfterOperation
.
fire
(
new
FileOperationEvent
(
resource
,
FileOperation
.
DELETE
));
this
.
_onAfterOperation
.
fire
(
new
FileOperationEvent
(
resource
,
FileOperation
.
DELETE
));
});
});
});
});
...
@@ -483,7 +456,7 @@ export class RemoteFileService extends FileService {
...
@@ -483,7 +456,7 @@ export class RemoteFileService extends FileService {
// https://github.com/Microsoft/vscode/issues/41543
// https://github.com/Microsoft/vscode/issues/41543
return
this
.
resolveContent
(
source
,
{
acceptTextOnly
:
true
}).
then
(
content
=>
{
return
this
.
resolveContent
(
source
,
{
acceptTextOnly
:
true
}).
then
(
content
=>
{
return
this
.
_withProvider
(
target
).
then
(
provider
=>
{
return
this
.
_withProvider
(
target
).
then
(
provider
=>
{
return
this
.
_
doUpdateContent
(
provider
,
target
,
content
.
value
,
{
encoding
:
content
.
encoding
}).
then
(
fileStat
=>
{
return
this
.
_
writeFile
(
provider
,
target
,
content
.
value
,
{
encoding
:
content
.
encoding
}).
then
(
fileStat
=>
{
this
.
_onAfterOperation
.
fire
(
new
FileOperationEvent
(
source
,
FileOperation
.
COPY
,
fileStat
));
this
.
_onAfterOperation
.
fire
(
new
FileOperationEvent
(
source
,
FileOperation
.
COPY
,
fileStat
));
return
fileStat
;
return
fileStat
;
});
});
...
@@ -497,7 +470,6 @@ export class RemoteFileService extends FileService {
...
@@ -497,7 +470,6 @@ export class RemoteFileService extends FileService {
});
});
});
});
});
});
}
}
touchFile
(
resource
:
URI
):
TPromise
<
IFileStat
,
any
>
{
touchFile
(
resource
:
URI
):
TPromise
<
IFileStat
,
any
>
{
...
@@ -513,7 +485,7 @@ export class RemoteFileService extends FileService {
...
@@ -513,7 +485,7 @@ export class RemoteFileService extends FileService {
return
provider
.
stat
(
resource
).
then
(()
=>
{
return
provider
.
stat
(
resource
).
then
(()
=>
{
return
provider
.
utimes
(
resource
,
Date
.
now
(),
Date
.
now
());
return
provider
.
utimes
(
resource
,
Date
.
now
(),
Date
.
now
());
},
err
=>
{
},
err
=>
{
return
provider
.
write
(
resource
,
new
Uint8Array
(
0
));
return
provider
.
write
File
(
resource
,
new
Uint8Array
(
0
));
}).
then
(()
=>
{
}).
then
(()
=>
{
return
this
.
resolveFile
(
resource
);
return
this
.
resolveFile
(
resource
);
});
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录