Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
9ea81df9
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,体验更适合开发者的 AI 搜索 >>
提交
9ea81df9
编写于
2月 04, 2020
作者:
J
Jackson Kearl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Working directory in state that gives ts build error
上级
4fe7d7d1
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
137 addition
and
45 deletion
+137
-45
src/vs/workbench/contrib/searchEditor/browser/constants.ts
src/vs/workbench/contrib/searchEditor/browser/constants.ts
+24
-0
src/vs/workbench/contrib/searchEditor/browser/searchEditor.ts
...vs/workbench/contrib/searchEditor/browser/searchEditor.ts
+4
-4
src/vs/workbench/contrib/searchEditor/browser/searchEditorInput.ts
...rkbench/contrib/searchEditor/browser/searchEditorInput.ts
+23
-29
src/vs/workbench/contrib/searchEditor/browser/searchEditorModel.ts
...rkbench/contrib/searchEditor/browser/searchEditorModel.ts
+84
-0
src/vs/workbench/contrib/searchEditor/browser/searchEditorSerialization.ts
...contrib/searchEditor/browser/searchEditorSerialization.ts
+2
-12
未找到文件。
src/vs/workbench/contrib/searchEditor/browser/constants.ts
浏览文件 @
9ea81df9
...
...
@@ -17,3 +17,27 @@ export const EnableSearchEditorPreview = new RawContextKey<boolean>('previewSear
export
const
InSearchEditor
=
new
RawContextKey
<
boolean
>
(
'
inSearchEditor
'
,
false
);
export
const
SearchEditorScheme
=
'
search-editor
'
;
export
type
SearchConfiguration
=
{
query
:
string
,
includes
:
string
,
excludes
:
string
contextLines
:
number
,
wholeWord
:
boolean
,
caseSensitive
:
boolean
,
regexp
:
boolean
,
useIgnores
:
boolean
,
showIncludesExcludes
:
boolean
,
};
export
const
DEFAULT_SEARCH_CONFIG
:
Readonly
<
SearchConfiguration
>
=
{
query
:
''
,
includes
:
''
,
excludes
:
''
,
contextLines
:
0
,
wholeWord
:
false
,
caseSensitive
:
false
,
regexp
:
false
,
useIgnores
:
true
,
showIncludesExcludes
:
false
,
};
src/vs/workbench/contrib/searchEditor/browser/searchEditor.ts
浏览文件 @
9ea81df9
...
...
@@ -38,11 +38,11 @@ import { serializeSearchResultForEditor } from 'vs/workbench/contrib/searchEdito
import
{
IContextKeyService
,
IContextKey
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
InputBoxFocusedKey
}
from
'
vs/workbench/contrib/search/common/constants
'
;
import
{
IEditorProgressService
,
LongRunningOperation
}
from
'
vs/platform/progress/common/progress
'
;
import
type
{
SearchEditorInput
,
SearchConfiguration
}
from
'
vs/workbench/contrib/searchEditor/browser/searchEditorInput
'
;
import
type
{
SearchEditorInput
}
from
'
vs/workbench/contrib/searchEditor/browser/searchEditorInput
'
;
import
{
searchEditorFindMatchBorder
,
searchEditorFindMatch
,
registerColor
,
inputBorder
}
from
'
vs/platform/theme/common/colorRegistry
'
;
import
{
attachInputBoxStyler
}
from
'
vs/platform/theme/common/styler
'
;
import
{
ReferencesController
}
from
'
vs/editor/contrib/gotoSymbol/peek/referencesController
'
;
import
{
InSearchEditor
}
from
'
vs/workbench/contrib/searchEditor/browser/constants
'
;
import
{
InSearchEditor
,
SearchConfiguration
}
from
'
vs/workbench/contrib/searchEditor/browser/constants
'
;
const
RESULT_LINE_REGEX
=
/^
(\s
+
)(\d
+
)(
:|
)(\s
+
)(
.*
)
$/
;
const
FILE_LINE_REGEX
=
/^
(\S
.*
)
:$/
;
...
...
@@ -334,7 +334,7 @@ export class SearchEditor extends BaseEditor {
controller
.
closeWidget
(
false
);
const
labelFormatter
=
(
uri
:
URI
):
string
=>
this
.
labelService
.
getUriLabel
(
uri
,
{
relative
:
true
});
const
results
=
serializeSearchResultForEditor
(
searchModel
.
searchResult
,
config
.
includes
,
config
.
excludes
,
config
.
contextLines
,
labelFormatter
,
tru
e
);
const
results
=
serializeSearchResultForEditor
(
searchModel
.
searchResult
,
config
.
includes
,
config
.
excludes
,
config
.
contextLines
,
labelFormatter
,
fals
e
);
const
textModel
=
assertIsDefined
(
this
.
searchResultEditor
.
getModel
());
this
.
modelService
.
updateModel
(
textModel
,
results
.
text
);
this
.
getInput
()?.
setDirty
(
this
.
getInput
()?.
resource
.
scheme
!==
'
search-editor
'
);
...
...
@@ -377,7 +377,7 @@ export class SearchEditor extends BaseEditor {
await
super
.
setInput
(
newInput
,
options
,
token
);
this
.
inSearchEditorContextKey
.
set
(
true
);
const
{
model
,
query
}
=
await
newInput
.
reloadModel
();
const
{
resultsTextModel
:
model
,
searchConfig
:
query
}
=
await
newInput
.
reloadModel
();
this
.
searchResultEditor
.
setModel
(
model
);
this
.
pauseSearching
=
true
;
...
...
src/vs/workbench/contrib/searchEditor/browser/searchEditorInput.ts
浏览文件 @
9ea81df9
...
...
@@ -10,14 +10,15 @@ import { isEqual, joinPath, toLocalResource } from 'vs/base/common/resources';
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
'
vs/css!./media/searchEditor
'
;
import
type
{
ICodeEditorViewState
}
from
'
vs/editor/common/editorCommon
'
;
import
{
IModelDeltaDecoration
,
ITextBufferFactory
,
ITextModel
}
from
'
vs/editor/common/model
'
;
import
{
IModelDeltaDecoration
,
ITextBufferFactory
}
from
'
vs/editor/common/model
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
import
{
localize
}
from
'
vs/nls
'
;
import
{
IFileDialogService
}
from
'
vs/platform/dialogs/common/dialogs
'
;
import
{
IInstantiationService
,
ServicesAccessor
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
ITelemetryService
}
from
'
vs/platform/telemetry/common/telemetry
'
;
import
{
EditorInput
,
GroupIdentifier
,
IEditorInput
,
IRevertOptions
,
ISaveOptions
}
from
'
vs/workbench/common/editor
'
;
import
{
SearchEditorScheme
,
SearchConfiguration
}
from
'
vs/workbench/contrib/searchEditor/browser/constants
'
;
import
{
SearchEditorModel
}
from
'
vs/workbench/contrib/searchEditor/browser/searchEditorModel
'
;
import
{
extractSearchQuery
,
serializeSearchConfiguration
}
from
'
vs/workbench/contrib/searchEditor/browser/searchEditorSerialization
'
;
import
{
IBackupFileService
}
from
'
vs/workbench/services/backup/common/backup
'
;
import
{
IEditorGroupsService
}
from
'
vs/workbench/services/editor/common/editorGroupsService
'
;
...
...
@@ -26,19 +27,6 @@ import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/
import
{
AutoSaveMode
,
IFilesConfigurationService
}
from
'
vs/workbench/services/filesConfiguration/common/filesConfigurationService
'
;
import
{
ITextFileSaveOptions
,
ITextFileService
}
from
'
vs/workbench/services/textfile/common/textfiles
'
;
import
{
IWorkingCopy
,
IWorkingCopyBackup
,
IWorkingCopyService
,
WorkingCopyCapabilities
}
from
'
vs/workbench/services/workingCopy/common/workingCopyService
'
;
import
{
SearchEditorScheme
}
from
'
vs/workbench/contrib/searchEditor/browser/constants
'
;
export
type
SearchConfiguration
=
{
query
:
string
,
includes
:
string
,
excludes
:
string
contextLines
:
number
,
wholeWord
:
boolean
,
caseSensitive
:
boolean
,
regexp
:
boolean
,
useIgnores
:
boolean
,
showIncludesExcludes
:
boolean
,
};
type
SearchEditorViewState
=
|
{
focused
:
'
input
'
}
...
...
@@ -48,7 +36,7 @@ export class SearchEditorInput extends EditorInput {
static
readonly
ID
:
string
=
'
workbench.editorinputs.searchEditorInput
'
;
private
dirty
:
boolean
=
false
;
private
readonly
model
:
Promise
<
IText
Model
>
;
private
readonly
model
:
Promise
<
SearchEditor
Model
>
;
private
query
:
Partial
<
SearchConfiguration
>
|
undefined
;
private
readonly
_onDidChangeContent
=
new
Emitter
<
void
>
();
...
...
@@ -60,7 +48,7 @@ export class SearchEditorInput extends EditorInput {
constructor
(
public
readonly
resource
:
URI
,
getModel
:
()
=>
Promise
<
IText
Model
>
,
getModel
:
()
=>
Promise
<
SearchEditor
Model
>
,
startingConfig
:
Partial
<
SearchConfiguration
>
|
undefined
,
@
IModelService
private
readonly
modelService
:
IModelService
,
@
IEditorService
protected
readonly
editorService
:
IEditorService
,
...
...
@@ -77,7 +65,8 @@ export class SearchEditorInput extends EditorInput {
this
.
model
=
getModel
()
.
then
(
model
=>
{
this
.
_register
(
model
.
onDidChangeContent
(()
=>
this
.
_onDidChangeContent
.
fire
()));
this
.
_register
(
model
.
resultsTextModel
.
onDidChangeContent
(()
=>
this
.
_onDidChangeContent
.
fire
()));
this
.
_register
(
model
);
return
model
;
});
...
...
@@ -109,7 +98,7 @@ export class SearchEditorInput extends EditorInput {
if
(
this
.
isUntitled
())
{
return
this
.
saveAs
(
group
,
options
);
}
else
{
await
this
.
textFileService
.
write
(
this
.
resource
,
(
await
this
.
model
).
getValue
(),
options
);
await
this
.
textFileService
.
write
(
this
.
resource
,
(
await
this
.
model
).
createSnapshot
(),
options
);
this
.
setDirty
(
false
);
return
this
;
}
...
...
@@ -122,7 +111,7 @@ export class SearchEditorInput extends EditorInput {
if
(
await
this
.
textFileService
.
saveAs
(
this
.
resource
,
path
,
options
))
{
this
.
setDirty
(
false
);
if
(
!
isEqual
(
path
,
this
.
resource
))
{
const
input
=
this
.
instantiationService
.
invokeFunction
(
getOrMakeSearchEditorInput
,
{
uri
:
path
});
const
input
=
this
.
instantiationService
.
invokeFunction
(
getOrMakeSearchEditorInput
,
{
uri
:
path
,
config
:
{
...
this
.
query
}
});
input
.
setHighlights
(
this
.
highlights
);
return
input
;
}
...
...
@@ -152,12 +141,15 @@ export class SearchEditorInput extends EditorInput {
async
reloadModel
()
{
const
model
=
await
this
.
model
;
const
query
=
extractSearchQuery
(
model
);
this
.
query
=
query
;
this
.
_highlights
=
model
.
getAllDecorations
();
this
.
query
=
model
.
searchConfig
;
this
.
_highlights
=
model
.
resultsTextModel
.
getAllDecorations
();
this
.
_onDidChangeLabel
.
fire
();
return
{
model
,
query
};
return
model
;
}
async
setConfig
(
config
:
Partial
<
SearchConfiguration
>
)
{
(
await
this
.
model
).
setConfig
(
config
);
}
getConfigSync
()
{
...
...
@@ -232,7 +224,7 @@ export class SearchEditorInput extends EditorInput {
public
async
setHighlights
(
value
:
IModelDeltaDecoration
[])
{
if
(
!
value
)
{
return
;
}
const
model
=
await
this
.
model
;
model
.
deltaDecorations
([],
value
);
model
.
resultsTextModel
.
deltaDecorations
([],
value
);
this
.
_highlights
=
value
;
}
...
...
@@ -251,7 +243,7 @@ export class SearchEditorInput extends EditorInput {
// Bringing this over from textFileService because it only suggests for untitled scheme.
// In the future I may just use the untitled scheme. I dont get particular benefit from using search-editor...
private
async
suggestFileName
():
Promise
<
URI
>
{
const
query
=
(
await
this
.
reloadModel
()).
query
.
query
;
const
query
=
(
await
this
.
reloadModel
()).
searchConfig
.
query
;
const
searchFileName
=
(
query
.
replace
(
/
[^\w
\-
_
]
+/g
,
'
_
'
)
||
'
Search
'
)
+
'
.code-search
'
;
...
...
@@ -282,7 +274,6 @@ export const getOrMakeSearchEditorInput = (
const
modelService
=
accessor
.
get
(
IModelService
);
const
textFileService
=
accessor
.
get
(
ITextFileService
);
const
backupService
=
accessor
.
get
(
IBackupFileService
);
const
modeService
=
accessor
.
get
(
IModeService
);
const
existing
=
inputs
.
get
(
uri
.
toString
());
if
(
existing
)
{
...
...
@@ -292,8 +283,11 @@ export const getOrMakeSearchEditorInput = (
const
config
=
existingData
.
config
??
(
existingData
.
text
?
extractSearchQuery
(
existingData
.
text
)
:
{});
const
getModel
=
async
()
=>
{
const
existing
=
modelService
.
getModel
(
uri
);
if
(
existing
)
{
return
existing
;
}
if
(
existing
)
{
return
instantiationService
.
createInstance
(
SearchEditorModel
,
{
resultsTextModel
:
existing
,
searchConfig
:
config
},
uri
);
}
const
backup
=
await
backupService
.
resolve
(
uri
);
backupService
.
discardBackup
(
uri
);
...
...
@@ -312,7 +306,7 @@ export const getOrMakeSearchEditorInput = (
throw
new
Error
(
'
no initial contents for search editor
'
);
}
return
modelService
.
createModel
(
contents
,
modeService
.
create
(
'
search-result
'
)
,
uri
);
return
instantiationService
.
createInstance
(
SearchEditorModel
,
{
rawTextModel
:
contents
}
,
uri
);
};
const
input
=
instantiationService
.
createInstance
(
SearchEditorInput
,
uri
,
getModel
,
config
);
...
...
src/vs/workbench/contrib/searchEditor/browser/searchEditorModel.ts
0 → 100644
浏览文件 @
9ea81df9
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
ITextModel
,
ITextBufferFactory
,
DefaultEndOfLine
,
ITextSnapshot
}
from
'
vs/editor/common/model
'
;
import
{
SearchConfiguration
,
DEFAULT_SEARCH_CONFIG
}
from
'
vs/workbench/contrib/searchEditor/browser/searchEditorInput
'
;
import
{
createTextBuffer
}
from
'
vs/editor/common/model/textModel
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
extractSearchQuery
,
serializeSearchConfiguration
}
from
'
vs/workbench/contrib/searchEditor/browser/searchEditorSerialization
'
;
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
stringToSnapshot
}
from
'
vs/workbench/services/textfile/common/textfiles
'
;
import
{
Event
,
Emitter
}
from
'
vs/base/common/event
'
;
type
SearchEditorModelConfig
=
|
{
rawTextModel
:
string
|
ITextBufferFactory
,
resultsTextModel
?:
never
,
searchConfig
?:
never
}
|
{
resultsTextModel
:
ITextModel
,
searchConfig
:
Partial
<
SearchConfiguration
>
,
rawTextModel
?:
never
}
;
export
class
SearchEditorModel
extends
Disposable
{
public
resultsTextModel
:
ITextModel
;
public
searchConfig
!
:
SearchConfiguration
;
private
readonly
_onDispose
=
new
Emitter
<
void
>
();
readonly
onDispose
:
Event
<
void
>
=
this
.
_onDispose
.
event
;
constructor
(
config
:
SearchEditorModelConfig
,
uri
:
URI
,
@
IModelService
private
readonly
modelService
:
IModelService
,
@
IModeService
private
readonly
modeService
:
IModeService
,
)
{
super
();
if
(
config
.
rawTextModel
!==
undefined
)
{
const
buffer
=
createTextBuffer
(
config
.
rawTextModel
,
DefaultEndOfLine
.
LF
);
const
header
=
[];
const
body
=
[];
let
inHeader
=
true
;
for
(
const
line
of
buffer
.
getLinesContent
())
{
if
(
inHeader
)
{
if
(
line
.
startsWith
(
'
#
'
))
{
header
.
push
(
line
);
}
else
if
(
line
===
''
)
{
inHeader
=
false
;
}
}
else
{
body
.
push
(
line
);
}
}
this
.
searchConfig
=
extractSearchQuery
(
header
.
join
(
'
\n
'
));
this
.
resultsTextModel
=
this
.
modelService
.
createModel
(
body
.
join
(
'
\n
'
),
this
.
modeService
.
create
(
'
search-result
'
),
uri
);
}
else
{
this
.
resultsTextModel
=
config
.
resultsTextModel
;
this
.
setConfig
(
config
.
searchConfig
);
}
this
.
_register
(
this
.
resultsTextModel
);
}
setConfig
(
config
:
Partial
<
SearchConfiguration
>
)
{
this
.
searchConfig
=
{
...
DEFAULT_SEARCH_CONFIG
,
...
config
};
}
createSnapshot
():
ITextSnapshot
{
return
stringToSnapshot
(
serializeSearchConfiguration
(
this
.
searchConfig
)
+
this
.
resultsTextModel
.
getValue
());
}
isDisposed
()
{
return
this
.
resultsTextModel
.
isDisposed
();
}
async
load
()
{
return
this
.
resultsTextModel
;
}
}
src/vs/workbench/contrib/searchEditor/browser/searchEditorSerialization.ts
浏览文件 @
9ea81df9
...
...
@@ -12,7 +12,7 @@ import { FileMatch, Match, searchMatchComparer, SearchResult } from 'vs/workbenc
import
{
ITextQuery
}
from
'
vs/workbench/services/search/common/search
'
;
import
{
localize
}
from
'
vs/nls
'
;
import
type
{
ITextModel
}
from
'
vs/editor/common/model
'
;
import
type
{
SearchConfiguration
}
from
'
vs/workbench/contrib/searchEditor/browser/searchEditorInput
'
;
import
{
SearchConfiguration
,
DEFAULT_SEARCH_CONFIG
}
from
'
vs/workbench/contrib/searchEditor/browser/searchEditorInput
'
;
// Using \r\n on Windows inserts an extra newline between results.
const
lineDelimiter
=
'
\n
'
;
...
...
@@ -146,17 +146,7 @@ export const extractSearchQuery = (model: ITextModel | string): SearchConfigurat
?
model
:
model
.
getValueInRange
(
new
Range
(
1
,
1
,
6
,
1
)).
split
(
lineDelimiter
);
const
query
:
SearchConfiguration
=
{
query
:
''
,
includes
:
''
,
excludes
:
''
,
regexp
:
false
,
caseSensitive
:
false
,
useIgnores
:
true
,
wholeWord
:
false
,
contextLines
:
0
,
showIncludesExcludes
:
false
,
};
const
query
:
SearchConfiguration
=
{
...
DEFAULT_SEARCH_CONFIG
};
const
unescapeNewlines
=
(
str
:
string
)
=>
{
let
out
=
''
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录