Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
4f6b6769
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4f6b6769
编写于
3月 03, 2020
作者:
S
Sandeep Somavarapu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#89512 support edit setting
上级
1d8df428
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
72 addition
and
59 deletion
+72
-59
src/vs/workbench/browser/parts/editor/editorStatus.ts
src/vs/workbench/browser/parts/editor/editorStatus.ts
+1
-1
src/vs/workbench/contrib/preferences/browser/preferencesActions.ts
...rkbench/contrib/preferences/browser/preferencesActions.ts
+1
-1
src/vs/workbench/services/configuration/common/jsonEditingService.ts
...bench/services/configuration/common/jsonEditingService.ts
+3
-3
src/vs/workbench/services/preferences/browser/preferencesService.ts
...kbench/services/preferences/browser/preferencesService.ts
+64
-52
src/vs/workbench/services/preferences/common/preferences.ts
src/vs/workbench/services/preferences/common/preferences.ts
+3
-2
未找到文件。
src/vs/workbench/browser/parts/editor/editorStatus.ts
浏览文件 @
4f6b6769
...
...
@@ -1137,7 +1137,7 @@ export class ChangeModeAction extends Action {
// User decided to configure settings for current language
if
(
pick
===
configureModeSettings
)
{
this
.
preferencesService
.
configureSettingsForLanguage
(
withUndefinedAsNull
(
modeId
)
);
this
.
preferencesService
.
openGlobalSettings
(
true
,
{
editSetting
:
`[
${
withUndefinedAsNull
(
modeId
)}
]`
}
);
return
;
}
...
...
src/vs/workbench/contrib/preferences/browser/preferencesActions.ts
浏览文件 @
4f6b6769
...
...
@@ -270,7 +270,7 @@ export class ConfigureLanguageBasedSettingsAction extends Action {
if
(
pick
)
{
const
modeId
=
this
.
modeService
.
getModeIdForLanguageName
(
pick
.
label
.
toLowerCase
());
if
(
typeof
modeId
===
'
string
'
)
{
return
this
.
preferencesService
.
configureSettingsForLanguage
(
modeId
);
return
this
.
preferencesService
.
openGlobalSettings
(
true
,
{
editSetting
:
`[
${
modeId
}
]`
}
);
}
}
return
undefined
;
...
...
src/vs/workbench/services/configuration/common/jsonEditingService.ts
浏览文件 @
4f6b6769
...
...
@@ -41,18 +41,18 @@ export class JSONEditingService implements IJSONEditingService {
private
async
doWriteConfiguration
(
resource
:
URI
,
values
:
IJSONValue
[],
save
:
boolean
):
Promise
<
void
>
{
const
reference
=
await
this
.
resolveAndValidate
(
resource
,
save
);
await
this
.
writeToBuffer
(
reference
.
object
.
textEditorModel
,
values
);
await
this
.
writeToBuffer
(
reference
.
object
.
textEditorModel
,
values
,
save
);
reference
.
dispose
();
}
private
async
writeToBuffer
(
model
:
ITextModel
,
values
:
IJSONValue
[]):
Promise
<
any
>
{
private
async
writeToBuffer
(
model
:
ITextModel
,
values
:
IJSONValue
[]
,
save
:
boolean
):
Promise
<
any
>
{
let
hasEdits
:
boolean
=
false
;
for
(
const
value
of
values
)
{
const
edit
=
this
.
getEdits
(
model
,
value
)[
0
];
hasEdits
=
this
.
applyEditsToBuffer
(
edit
,
model
);
}
if
(
hasEdits
)
{
if
(
hasEdits
&&
save
)
{
return
this
.
textFileService
.
save
(
model
.
uri
);
}
}
...
...
src/vs/workbench/services/preferences/browser/preferencesService.ts
浏览文件 @
4f6b6769
...
...
@@ -8,11 +8,9 @@ import { parse } from 'vs/base/common/json';
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
*
as
network
from
'
vs/base/common/network
'
;
import
{
assign
}
from
'
vs/base/common/objects
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
getCodeEditor
,
ICodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
EditOperation
}
from
'
vs/editor/common/core/editOperation
'
;
import
{
IPosition
,
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
IPosition
}
from
'
vs/editor/common/core/position
'
;
import
{
ITextModel
}
from
'
vs/editor/common/model
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
...
...
@@ -39,6 +37,10 @@ import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import
{
IRemoteAgentService
}
from
'
vs/workbench/services/remote/common/remoteAgentService
'
;
import
{
ITextFileService
}
from
'
vs/workbench/services/textfile/common/textfiles
'
;
import
{
withNullAsUndefined
}
from
'
vs/base/common/types
'
;
import
{
getDefaultValue
,
IConfigurationRegistry
,
Extensions
,
OVERRIDE_PROPERTY_PATTERN
}
from
'
vs/platform/configuration/common/configurationRegistry
'
;
import
{
Registry
}
from
'
vs/platform/registry/common/platform
'
;
import
{
ICommandService
}
from
'
vs/platform/commands/common/commands
'
;
import
{
CoreEditingCommands
}
from
'
vs/editor/browser/controller/coreCommands
'
;
const
emptyEditableSettingsContent
=
'
{
\n
}
'
;
...
...
@@ -73,7 +75,8 @@ export class PreferencesService extends Disposable implements IPreferencesServic
@
IJSONEditingService
private
readonly
jsonEditingService
:
IJSONEditingService
,
@
IModeService
private
readonly
modeService
:
IModeService
,
@
ILabelService
private
readonly
labelService
:
ILabelService
,
@
IRemoteAgentService
private
readonly
remoteAgentService
:
IRemoteAgentService
@
IRemoteAgentService
private
readonly
remoteAgentService
:
IRemoteAgentService
,
@
ICommandService
private
readonly
commandService
:
ICommandService
,
)
{
super
();
// The default keybindings.json updates based on keyboard layouts, so here we make sure
...
...
@@ -311,25 +314,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic
return
this
.
editorService
.
openEditor
({
resource
:
this
.
defaultKeybindingsResource
,
label
:
nls
.
localize
(
'
defaultKeybindings
'
,
"
Default Keybindings
"
)
});
}
configureSettingsForLanguage
(
language
:
string
):
void
{
this
.
openGlobalSettings
(
true
)
.
then
(
editor
=>
this
.
createPreferencesEditorModel
(
this
.
userSettingsResource
)
.
then
((
settingsModel
:
IPreferencesEditorModel
<
ISetting
>
|
null
)
=>
{
const
codeEditor
=
editor
?
getCodeEditor
(
editor
.
getControl
())
:
null
;
if
(
codeEditor
&&
settingsModel
)
{
this
.
addLanguageOverrideEntry
(
language
,
settingsModel
,
codeEditor
)
.
then
(
position
=>
{
if
(
codeEditor
&&
position
)
{
codeEditor
.
setPosition
(
position
);
codeEditor
.
revealLine
(
position
.
lineNumber
);
codeEditor
.
focus
();
}
});
}
}));
}
private
openOrSwitchSettings
(
configurationTarget
:
ConfigurationTarget
,
resource
:
URI
,
options
?:
ISettingsEditorOptions
,
group
:
IEditorGroup
=
this
.
editorGroupService
.
activeGroup
):
Promise
<
IEditorPane
|
undefined
>
{
private
async
openOrSwitchSettings
(
configurationTarget
:
ConfigurationTarget
,
resource
:
URI
,
options
?:
ISettingsEditorOptions
,
group
:
IEditorGroup
=
this
.
editorGroupService
.
activeGroup
):
Promise
<
IEditorPane
|
undefined
>
{
const
editorInput
=
this
.
getActiveSettingsEditorInput
(
group
);
if
(
editorInput
)
{
const
editorInputResource
=
editorInput
.
master
.
resource
;
...
...
@@ -337,7 +322,11 @@ export class PreferencesService extends Disposable implements IPreferencesServic
return
this
.
doSwitchSettings
(
configurationTarget
,
resource
,
editorInput
,
group
,
options
);
}
}
return
this
.
doOpenSettings
(
configurationTarget
,
resource
,
options
,
group
);
const
editor
=
await
this
.
doOpenSettings
(
configurationTarget
,
resource
,
options
,
group
);
if
(
editor
&&
options
?.
editSetting
)
{
await
this
.
editSetting
(
options
?.
editSetting
,
editor
,
resource
);
}
return
editor
;
}
private
openOrSwitchSettings2
(
configurationTarget
:
ConfigurationTarget
,
folderUri
?:
URI
,
options
?:
ISettingsEditorOptions
,
group
:
IEditorGroup
=
this
.
editorGroupService
.
activeGroup
):
Promise
<
IEditorPane
|
undefined
>
{
...
...
@@ -593,39 +582,62 @@ export class PreferencesService extends Disposable implements IPreferencesServic
];
}
private
addLanguageOverrideEntry
(
language
:
string
,
settingsModel
:
IPreferencesEditorModel
<
ISetting
>
,
codeEditor
:
ICodeEditor
):
Promise
<
IPosition
|
null
>
{
const
languageKey
=
`[
${
language
}
]`
;
let
setting
=
settingsModel
.
getPreference
(
languageKey
);
private
async
editSetting
(
settingKey
:
string
,
editor
:
IEditorPane
,
settingsResource
:
URI
):
Promise
<
void
>
{
const
codeEditor
=
editor
?
getCodeEditor
(
editor
.
getControl
())
:
null
;
if
(
!
codeEditor
)
{
return
;
}
const
settingsModel
=
await
this
.
createPreferencesEditorModel
(
settingsResource
);
if
(
!
settingsModel
)
{
return
;
}
const
position
=
await
this
.
getPositionToEdit
(
settingKey
,
settingsModel
,
codeEditor
);
if
(
position
)
{
codeEditor
.
setPosition
(
position
);
codeEditor
.
revealPositionNearTop
(
position
);
codeEditor
.
focus
();
await
this
.
commandService
.
executeCommand
(
'
editor.action.triggerSuggest
'
);
}
}
private
async
getPositionToEdit
(
settingKey
:
string
,
settingsModel
:
IPreferencesEditorModel
<
ISetting
>
,
codeEditor
:
ICodeEditor
):
Promise
<
IPosition
|
null
>
{
const
model
=
codeEditor
.
getModel
();
if
(
model
)
{
const
configuration
=
this
.
configurationService
.
getValue
<
{
editor
:
{
tabSize
:
number
;
insertSpaces
:
boolean
}
}
>
();
const
eol
=
model
.
getEOL
();
if
(
setting
)
{
if
(
setting
.
overrides
&&
setting
.
overrides
.
length
)
{
const
lastSetting
=
setting
.
overrides
[
setting
.
overrides
.
length
-
1
];
return
Promise
.
resolve
({
lineNumber
:
lastSetting
.
valueRange
.
endLineNumber
,
column
:
model
.
getLineMaxColumn
(
lastSetting
.
valueRange
.
endLineNumber
)
});
if
(
!
model
)
{
return
null
;
}
const
schema
=
Registry
.
as
<
IConfigurationRegistry
>
(
Extensions
.
Configuration
).
getConfigurationProperties
()[
settingKey
];
if
(
!
schema
&&
!
OVERRIDE_PROPERTY_PATTERN
.
test
(
settingKey
))
{
return
null
;
}
let
position
=
null
;
const
type
=
schema
?
schema
.
type
:
'
object
'
/* Override Identifier */
;
let
setting
=
settingsModel
.
getPreference
(
settingKey
);
if
(
!
setting
)
{
const
defaultValue
=
type
===
'
array
'
?
this
.
configurationService
.
inspect
(
settingKey
).
defaultValue
:
getDefaultValue
(
type
);
if
(
defaultValue
!==
undefined
)
{
await
this
.
jsonEditingService
.
write
(
settingsModel
.
uri
!
,
[{
key
:
settingKey
,
value
:
defaultValue
}],
false
);
setting
=
settingsModel
.
getPreference
(
settingKey
);
}
}
if
(
setting
)
{
position
=
{
lineNumber
:
setting
.
valueRange
.
startLineNumber
,
column
:
setting
.
valueRange
.
startColumn
+
1
};
if
(
type
===
'
object
'
||
type
===
'
array
'
)
{
codeEditor
.
setPosition
(
position
);
await
CoreEditingCommands
.
LineBreakInsert
.
runEditorCommand
(
null
,
codeEditor
,
null
);
position
=
{
lineNumber
:
position
.
lineNumber
+
1
,
column
:
model
.
getLineMaxColumn
(
position
.
lineNumber
+
1
)
};
const
firstNonWhiteSpaceColumn
=
model
.
getLineFirstNonWhitespaceColumn
(
position
.
lineNumber
);
if
(
firstNonWhiteSpaceColumn
)
{
// Line has some text. Insert another new line.
codeEditor
.
setPosition
({
lineNumber
:
position
.
lineNumber
,
column
:
firstNonWhiteSpaceColumn
});
await
CoreEditingCommands
.
LineBreakInsert
.
runEditorCommand
(
null
,
codeEditor
,
null
);
position
=
{
lineNumber
:
position
.
lineNumber
,
column
:
model
.
getLineMaxColumn
(
position
.
lineNumber
)
};
}
return
Promise
.
resolve
({
lineNumber
:
setting
.
valueRange
.
startLineNumber
,
column
:
setting
.
valueRange
.
startColumn
+
1
});
}
return
this
.
configurationService
.
updateValue
(
languageKey
,
{},
ConfigurationTarget
.
USER
)
.
then
(()
=>
{
setting
=
settingsModel
.
getPreference
(
languageKey
);
if
(
setting
)
{
let
content
=
eol
+
this
.
spaces
(
2
,
configuration
.
editor
)
+
eol
+
this
.
spaces
(
1
,
configuration
.
editor
);
let
editOperation
=
EditOperation
.
insert
(
new
Position
(
setting
.
valueRange
.
endLineNumber
,
setting
.
valueRange
.
endColumn
-
1
),
content
);
model
.
pushEditOperations
([],
[
editOperation
],
()
=>
[]);
let
lineNumber
=
setting
.
valueRange
.
endLineNumber
+
1
;
settingsModel
.
dispose
();
return
{
lineNumber
,
column
:
model
.
getLineMaxColumn
(
lineNumber
)
};
}
return
null
;
});
}
return
Promise
.
resolve
(
null
);
}
private
spaces
(
count
:
number
,
{
tabSize
,
insertSpaces
}:
{
tabSize
:
number
;
insertSpaces
:
boolean
}):
string
{
return
insertSpaces
?
strings
.
repeat
(
'
'
,
tabSize
*
count
)
:
strings
.
repeat
(
'
\t
'
,
count
);
return
position
;
}
public
dispose
():
void
{
...
...
src/vs/workbench/services/preferences/common/preferences.ts
浏览文件 @
4f6b6769
...
...
@@ -155,6 +155,7 @@ export interface ISettingsEditorOptions extends IEditorOptions {
target
?:
ConfigurationTarget
;
folderUri
?:
URI
;
query
?:
string
;
editSetting
?:
string
;
}
/**
...
...
@@ -165,6 +166,7 @@ export class SettingsEditorOptions extends EditorOptions implements ISettingsEdi
target
?:
ConfigurationTarget
;
folderUri
?:
URI
;
query
?:
string
;
editSetting
?:
string
;
static
create
(
settings
:
ISettingsEditorOptions
):
SettingsEditorOptions
{
const
options
=
new
SettingsEditorOptions
();
...
...
@@ -173,6 +175,7 @@ export class SettingsEditorOptions extends EditorOptions implements ISettingsEdi
options
.
target
=
settings
.
target
;
options
.
folderUri
=
settings
.
folderUri
;
options
.
query
=
settings
.
query
;
options
.
editSetting
=
settings
.
editSetting
;
return
options
;
}
...
...
@@ -203,8 +206,6 @@ export interface IPreferencesService {
switchSettings
(
target
:
ConfigurationTarget
,
resource
:
URI
,
jsonEditor
?:
boolean
):
Promise
<
void
>
;
openGlobalKeybindingSettings
(
textual
:
boolean
):
Promise
<
void
>
;
openDefaultKeybindingsFile
():
Promise
<
IEditorPane
|
undefined
>
;
configureSettingsForLanguage
(
language
:
string
|
null
):
void
;
}
export
function
getSettingsTargetName
(
target
:
ConfigurationTarget
,
resource
:
URI
,
workspaceContextService
:
IWorkspaceContextService
):
string
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录