Открыть боковую панель
code
vscode
Коммиты
c1cc1a90
Не подтверждена
Коммит
c1cc1a90
создал
Апр 29, 2024
по автору
Matt Bierner
Зафиксировано автором
GitHub
Апр 29, 2024
Просмотр файлов
Remove most `<type>` assertions in TS ext (#211648)
These can easily hide typing errors
владелец
ba7b9278
Изменения
3
Скрыть пробелы
Построчно
Рядом
extensions/typescript-language-features/src/commands/openJsDocLink.ts
Просмотр файла @
c1cc1a90
...
...
@@ -32,8 +32,8 @@ export class OpenJsDocLinkCommand implements Command {
public
async
execute
(
args
:
OpenJsDocLinkCommand_Args
):
Promise
<
void
>
{
const
{
line
,
character
}
=
args
.
position
;
const
position
=
new
vscode
.
Position
(
line
,
character
);
await
vscode
.
commands
.
executeCommand
(
'
vscode.open
'
,
vscode
.
Uri
.
from
(
args
.
file
),
<
vscode
.
TextDocumentShowOptions
>
{
await
vscode
.
commands
.
executeCommand
(
'
vscode.open
'
,
vscode
.
Uri
.
from
(
args
.
file
),
{
selection
:
new
vscode
.
Range
(
position
,
position
),
});
}
satisfies
vscode
.
TextDocumentShowOptions
);
}
}
extensions/typescript-language-features/src/filesystems/memFs.ts
Просмотр файла @
c1cc1a90
...
...
@@ -8,7 +8,7 @@ import { basename, dirname } from 'path';
export
class
MemFs
implements
vscode
.
FileSystemProvider
{
private
readonly
root
=
new
FsEntry
(
private
readonly
root
=
new
Fs
Directory
Entry
(
new
Map
(),
0
,
0
,
...
...
@@ -31,8 +31,11 @@ export class MemFs implements vscode.FileSystemProvider {
if
(
!
entry
)
{
throw
vscode
.
FileSystemError
.
FileNotFound
();
}
if
(
!
(
entry
instanceof
FsDirectoryEntry
))
{
throw
vscode
.
FileSystemError
.
FileNotADirectory
();
}
return
[...
entry
.
contents
.
entries
()
].
map
(
([
name
,
entry
])
=>
[
name
,
entry
.
type
]);
return
Array
.
from
(
entry
.
contents
.
entries
()
,
([
name
,
entry
])
=>
[
name
,
entry
.
type
]);
}
readFile
(
uri
:
vscode
.
Uri
):
Uint8Array
{
...
...
@@ -43,6 +46,10 @@ export class MemFs implements vscode.FileSystemProvider {
throw
vscode
.
FileSystemError
.
FileNotFound
();
}
if
(
!
(
entry
instanceof
FsFileEntry
))
{
throw
vscode
.
FileSystemError
.
FileIsADirectory
(
uri
);
}
return
entry
.
data
;
}
...
...
@@ -58,12 +65,16 @@ export class MemFs implements vscode.FileSystemProvider {
const
entry
=
dirContents
.
get
(
basename
(
uri
.
path
));
if
(
!
entry
)
{
if
(
create
)
{
dirContents
.
set
(
fileName
,
new
FsEntry
(
content
,
time
,
time
));
dirContents
.
set
(
fileName
,
new
Fs
File
Entry
(
content
,
time
,
time
));
this
.
_emitter
.
fire
([{
type
:
vscode
.
FileChangeType
.
Created
,
uri
}]);
}
else
{
throw
vscode
.
FileSystemError
.
FileNotFound
();
}
}
else
{
if
(
entry
instanceof
FsDirectoryEntry
)
{
throw
vscode
.
FileSystemError
.
FileIsADirectory
(
uri
);
}
if
(
overwrite
)
{
entry
.
mtime
=
time
;
entry
.
data
=
content
;
...
...
@@ -90,10 +101,10 @@ export class MemFs implements vscode.FileSystemProvider {
// console.log('createDirectory', uri.toString());
const
dir
=
this
.
getParent
(
uri
);
const
now
=
Date
.
now
()
/
1000
;
dir
.
contents
.
set
(
basename
(
uri
.
path
),
new
FsEntry
(
new
Map
(),
now
,
now
));
dir
.
contents
.
set
(
basename
(
uri
.
path
),
new
Fs
Directory
Entry
(
new
Map
(),
now
,
now
));
}
private
getEntry
(
uri
:
vscode
.
Uri
):
FsEntry
|
voi
d
{
private
getEntry
(
uri
:
vscode
.
Uri
):
FsEntry
|
undefine
d
{
// TODO: have this throw FileNotFound itself?
// TODO: support configuring case sensitivity
let
node
:
FsEntry
=
this
.
root
;
...
...
@@ -104,13 +115,12 @@ export class MemFs implements vscode.FileSystemProvider {
continue
;
}
if
(
node
.
type
!==
vscode
.
FileType
.
Directory
)
{
if
(
!
(
node
instanceof
Fs
Directory
Entry
)
)
{
// We're looking at a File or such, so bail.
return
;
}
const
next
=
node
.
contents
.
get
(
component
);
if
(
!
next
)
{
// not found!
return
;
...
...
@@ -121,11 +131,14 @@ export class MemFs implements vscode.FileSystemProvider {
return
node
;
}
private
getParent
(
uri
:
vscode
.
Uri
)
{
private
getParent
(
uri
:
vscode
.
Uri
)
:
FsDirectoryEntry
{
const
dir
=
this
.
getEntry
(
uri
.
with
({
path
:
dirname
(
uri
.
path
)
}));
if
(
!
dir
)
{
throw
vscode
.
FileSystemError
.
FileNotFound
();
}
if
(
!
(
dir
instanceof
FsDirectoryEntry
))
{
throw
vscode
.
FileSystemError
.
FileNotADirectory
();
}
return
dir
;
}
...
...
@@ -153,46 +166,32 @@ export class MemFs implements vscode.FileSystemProvider {
}
}
class
FsEntry
{
get
type
():
vscode
.
FileType
{
if
(
this
.
_data
instanceof
Uint8Array
)
{
return
vscode
.
FileType
.
File
;
}
else
{
return
vscode
.
FileType
.
Directory
;
}
}
class
FsFileEntry
{
readonly
type
=
vscode
.
FileType
.
File
;
get
size
():
number
{
if
(
this
.
type
===
vscode
.
FileType
.
Directory
)
{
return
[...
this
.
contents
.
values
()].
reduce
((
acc
:
number
,
entry
:
FsEntry
)
=>
acc
+
entry
.
size
,
0
);
}
else
{
return
this
.
data
.
length
;
}
return
this
.
data
.
length
;
}
constructor
(
p
rivate
_
data
:
Uint8Array
|
Map
<
string
,
FsEntry
>
,
public
ctime
:
number
,
p
ublic
data
:
Uint8Array
,
public
readonly
ctime
:
number
,
public
mtime
:
number
,
)
{
}
}
get
data
()
{
if
(
this
.
type
===
vscode
.
FileType
.
Directory
)
{
throw
vscode
.
FileSystemError
.
FileIsADirectory
;
}
return
<
Uint8Array
>
this
.
_data
;
}
set
data
(
val
:
Uint8Array
)
{
if
(
this
.
type
===
vscode
.
FileType
.
Directory
)
{
throw
vscode
.
FileSystemError
.
FileIsADirectory
;
}
this
.
_data
=
val
;
}
class
FsDirectoryEntry
{
readonly
type
=
vscode
.
FileType
.
Directory
;
get
contents
()
{
if
(
this
.
type
!==
vscode
.
FileType
.
Directory
)
{
throw
vscode
.
FileSystemError
.
FileNotADirectory
;
}
return
<
Map
<
string
,
FsEntry
>>
this
.
_data
;
get
size
():
number
{
return
[...
this
.
contents
.
values
()].
reduce
((
acc
:
number
,
entry
:
FsEntry
)
=>
acc
+
entry
.
size
,
0
);
}
constructor
(
public
readonly
contents
:
Map
<
string
,
FsEntry
>
,
public
readonly
ctime
:
number
,
public
readonly
mtime
:
number
,
)
{
}
}
type
FsEntry
=
FsFileEntry
|
FsDirectoryEntry
;
extensions/typescript-language-features/src/utils/arrays.ts
Просмотр файла @
c1cc1a90
...
...
@@ -20,5 +20,5 @@ export function equals<T>(
}
export
function
coalesce
<
T
>
(
array
:
ReadonlyArray
<
T
|
undefined
>
):
T
[]
{
return
<
T
[]
>
array
.
filter
(
e
=>
!!
e
);
return
array
.
filter
(
(
e
):
e
is
T
=>
!!
e
);
}
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать