Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
4f6b6769
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,发现更多精彩内容 >>
提交
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 {
...
@@ -1137,7 +1137,7 @@ export class ChangeModeAction extends Action {
// User decided to configure settings for current language
// User decided to configure settings for current language
if
(
pick
===
configureModeSettings
)
{
if
(
pick
===
configureModeSettings
)
{
this
.
preferencesService
.
configureSettingsForLanguage
(
withUndefinedAsNull
(
modeId
)
);
this
.
preferencesService
.
openGlobalSettings
(
true
,
{
editSetting
:
`[
${
withUndefinedAsNull
(
modeId
)}
]`
}
);
return
;
return
;
}
}
...
...
src/vs/workbench/contrib/preferences/browser/preferencesActions.ts
浏览文件 @
4f6b6769
...
@@ -270,7 +270,7 @@ export class ConfigureLanguageBasedSettingsAction extends Action {
...
@@ -270,7 +270,7 @@ export class ConfigureLanguageBasedSettingsAction extends Action {
if
(
pick
)
{
if
(
pick
)
{
const
modeId
=
this
.
modeService
.
getModeIdForLanguageName
(
pick
.
label
.
toLowerCase
());
const
modeId
=
this
.
modeService
.
getModeIdForLanguageName
(
pick
.
label
.
toLowerCase
());
if
(
typeof
modeId
===
'
string
'
)
{
if
(
typeof
modeId
===
'
string
'
)
{
return
this
.
preferencesService
.
configureSettingsForLanguage
(
modeId
);
return
this
.
preferencesService
.
openGlobalSettings
(
true
,
{
editSetting
:
`[
${
modeId
}
]`
}
);
}
}
}
}
return
undefined
;
return
undefined
;
...
...
src/vs/workbench/services/configuration/common/jsonEditingService.ts
浏览文件 @
4f6b6769
...
@@ -41,18 +41,18 @@ export class JSONEditingService implements IJSONEditingService {
...
@@ -41,18 +41,18 @@ export class JSONEditingService implements IJSONEditingService {
private
async
doWriteConfiguration
(
resource
:
URI
,
values
:
IJSONValue
[],
save
:
boolean
):
Promise
<
void
>
{
private
async
doWriteConfiguration
(
resource
:
URI
,
values
:
IJSONValue
[],
save
:
boolean
):
Promise
<
void
>
{
const
reference
=
await
this
.
resolveAndValidate
(
resource
,
save
);
const
reference
=
await
this
.
resolveAndValidate
(
resource
,
save
);
await
this
.
writeToBuffer
(
reference
.
object
.
textEditorModel
,
values
);
await
this
.
writeToBuffer
(
reference
.
object
.
textEditorModel
,
values
,
save
);
reference
.
dispose
();
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
;
let
hasEdits
:
boolean
=
false
;
for
(
const
value
of
values
)
{
for
(
const
value
of
values
)
{
const
edit
=
this
.
getEdits
(
model
,
value
)[
0
];
const
edit
=
this
.
getEdits
(
model
,
value
)[
0
];
hasEdits
=
this
.
applyEditsToBuffer
(
edit
,
model
);
hasEdits
=
this
.
applyEditsToBuffer
(
edit
,
model
);
}
}
if
(
hasEdits
)
{
if
(
hasEdits
&&
save
)
{
return
this
.
textFileService
.
save
(
model
.
uri
);
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';
...
@@ -8,11 +8,9 @@ import { parse } from 'vs/base/common/json';
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
*
as
network
from
'
vs/base/common/network
'
;
import
*
as
network
from
'
vs/base/common/network
'
;
import
{
assign
}
from
'
vs/base/common/objects
'
;
import
{
assign
}
from
'
vs/base/common/objects
'
;
import
*
as
strings
from
'
vs/base/common/strings
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
getCodeEditor
,
ICodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
getCodeEditor
,
ICodeEditor
}
from
'
vs/editor/browser/editorBrowser
'
;
import
{
EditOperation
}
from
'
vs/editor/common/core/editOperation
'
;
import
{
IPosition
}
from
'
vs/editor/common/core/position
'
;
import
{
IPosition
,
Position
}
from
'
vs/editor/common/core/position
'
;
import
{
ITextModel
}
from
'
vs/editor/common/model
'
;
import
{
ITextModel
}
from
'
vs/editor/common/model
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
...
@@ -39,6 +37,10 @@ import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
...
@@ -39,6 +37,10 @@ import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import
{
IRemoteAgentService
}
from
'
vs/workbench/services/remote/common/remoteAgentService
'
;
import
{
IRemoteAgentService
}
from
'
vs/workbench/services/remote/common/remoteAgentService
'
;
import
{
ITextFileService
}
from
'
vs/workbench/services/textfile/common/textfiles
'
;
import
{
ITextFileService
}
from
'
vs/workbench/services/textfile/common/textfiles
'
;
import
{
withNullAsUndefined
}
from
'
vs/base/common/types
'
;
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
}
'
;
const
emptyEditableSettingsContent
=
'
{
\n
}
'
;
...
@@ -73,7 +75,8 @@ export class PreferencesService extends Disposable implements IPreferencesServic
...
@@ -73,7 +75,8 @@ export class PreferencesService extends Disposable implements IPreferencesServic
@
IJSONEditingService
private
readonly
jsonEditingService
:
IJSONEditingService
,
@
IJSONEditingService
private
readonly
jsonEditingService
:
IJSONEditingService
,
@
IModeService
private
readonly
modeService
:
IModeService
,
@
IModeService
private
readonly
modeService
:
IModeService
,
@
ILabelService
private
readonly
labelService
:
ILabelService
,
@
ILabelService
private
readonly
labelService
:
ILabelService
,
@
IRemoteAgentService
private
readonly
remoteAgentService
:
IRemoteAgentService
@
IRemoteAgentService
private
readonly
remoteAgentService
:
IRemoteAgentService
,
@
ICommandService
private
readonly
commandService
:
ICommandService
,
)
{
)
{
super
();
super
();
// The default keybindings.json updates based on keyboard layouts, so here we make sure
// 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
...
@@ -311,25 +314,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic
return
this
.
editorService
.
openEditor
({
resource
:
this
.
defaultKeybindingsResource
,
label
:
nls
.
localize
(
'
defaultKeybindings
'
,
"
Default Keybindings
"
)
});
return
this
.
editorService
.
openEditor
({
resource
:
this
.
defaultKeybindingsResource
,
label
:
nls
.
localize
(
'
defaultKeybindings
'
,
"
Default Keybindings
"
)
});
}
}
configureSettingsForLanguage
(
language
:
string
):
void
{
private
async
openOrSwitchSettings
(
configurationTarget
:
ConfigurationTarget
,
resource
:
URI
,
options
?:
ISettingsEditorOptions
,
group
:
IEditorGroup
=
this
.
editorGroupService
.
activeGroup
):
Promise
<
IEditorPane
|
undefined
>
{
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
>
{
const
editorInput
=
this
.
getActiveSettingsEditorInput
(
group
);
const
editorInput
=
this
.
getActiveSettingsEditorInput
(
group
);
if
(
editorInput
)
{
if
(
editorInput
)
{
const
editorInputResource
=
editorInput
.
master
.
resource
;
const
editorInputResource
=
editorInput
.
master
.
resource
;
...
@@ -337,7 +322,11 @@ export class PreferencesService extends Disposable implements IPreferencesServic
...
@@ -337,7 +322,11 @@ export class PreferencesService extends Disposable implements IPreferencesServic
return
this
.
doSwitchSettings
(
configurationTarget
,
resource
,
editorInput
,
group
,
options
);
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
>
{
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
...
@@ -593,39 +582,62 @@ export class PreferencesService extends Disposable implements IPreferencesServic
];
];
}
}
private
addLanguageOverrideEntry
(
language
:
string
,
settingsModel
:
IPreferencesEditorModel
<
ISetting
>
,
codeEditor
:
ICodeEditor
):
Promise
<
IPosition
|
null
>
{
private
async
editSetting
(
settingKey
:
string
,
editor
:
IEditorPane
,
settingsResource
:
URI
):
Promise
<
void
>
{
const
languageKey
=
`[
${
language
}
]`
;
const
codeEditor
=
editor
?
getCodeEditor
(
editor
.
getControl
())
:
null
;
let
setting
=
settingsModel
.
getPreference
(
languageKey
);
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
();
const
model
=
codeEditor
.
getModel
();
if
(
model
)
{
if
(
!
model
)
{
const
configuration
=
this
.
configurationService
.
getValue
<
{
editor
:
{
tabSize
:
number
;
insertSpaces
:
boolean
}
}
>
();
return
null
;
const
eol
=
model
.
getEOL
();
}
if
(
setting
)
{
const
schema
=
Registry
.
as
<
IConfigurationRegistry
>
(
Extensions
.
Configuration
).
getConfigurationProperties
()[
settingKey
];
if
(
setting
.
overrides
&&
setting
.
overrides
.
length
)
{
if
(
!
schema
&&
!
OVERRIDE_PROPERTY_PATTERN
.
test
(
settingKey
))
{
const
lastSetting
=
setting
.
overrides
[
setting
.
overrides
.
length
-
1
];
return
null
;
return
Promise
.
resolve
({
lineNumber
:
lastSetting
.
valueRange
.
endLineNumber
,
column
:
model
.
getLineMaxColumn
(
lastSetting
.
valueRange
.
endLineNumber
)
});
}
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
position
;
return
insertSpaces
?
strings
.
repeat
(
'
'
,
tabSize
*
count
)
:
strings
.
repeat
(
'
\t
'
,
count
);
}
}
public
dispose
():
void
{
public
dispose
():
void
{
...
...
src/vs/workbench/services/preferences/common/preferences.ts
浏览文件 @
4f6b6769
...
@@ -155,6 +155,7 @@ export interface ISettingsEditorOptions extends IEditorOptions {
...
@@ -155,6 +155,7 @@ export interface ISettingsEditorOptions extends IEditorOptions {
target
?:
ConfigurationTarget
;
target
?:
ConfigurationTarget
;
folderUri
?:
URI
;
folderUri
?:
URI
;
query
?:
string
;
query
?:
string
;
editSetting
?:
string
;
}
}
/**
/**
...
@@ -165,6 +166,7 @@ export class SettingsEditorOptions extends EditorOptions implements ISettingsEdi
...
@@ -165,6 +166,7 @@ export class SettingsEditorOptions extends EditorOptions implements ISettingsEdi
target
?:
ConfigurationTarget
;
target
?:
ConfigurationTarget
;
folderUri
?:
URI
;
folderUri
?:
URI
;
query
?:
string
;
query
?:
string
;
editSetting
?:
string
;
static
create
(
settings
:
ISettingsEditorOptions
):
SettingsEditorOptions
{
static
create
(
settings
:
ISettingsEditorOptions
):
SettingsEditorOptions
{
const
options
=
new
SettingsEditorOptions
();
const
options
=
new
SettingsEditorOptions
();
...
@@ -173,6 +175,7 @@ export class SettingsEditorOptions extends EditorOptions implements ISettingsEdi
...
@@ -173,6 +175,7 @@ export class SettingsEditorOptions extends EditorOptions implements ISettingsEdi
options
.
target
=
settings
.
target
;
options
.
target
=
settings
.
target
;
options
.
folderUri
=
settings
.
folderUri
;
options
.
folderUri
=
settings
.
folderUri
;
options
.
query
=
settings
.
query
;
options
.
query
=
settings
.
query
;
options
.
editSetting
=
settings
.
editSetting
;
return
options
;
return
options
;
}
}
...
@@ -203,8 +206,6 @@ export interface IPreferencesService {
...
@@ -203,8 +206,6 @@ export interface IPreferencesService {
switchSettings
(
target
:
ConfigurationTarget
,
resource
:
URI
,
jsonEditor
?:
boolean
):
Promise
<
void
>
;
switchSettings
(
target
:
ConfigurationTarget
,
resource
:
URI
,
jsonEditor
?:
boolean
):
Promise
<
void
>
;
openGlobalKeybindingSettings
(
textual
:
boolean
):
Promise
<
void
>
;
openGlobalKeybindingSettings
(
textual
:
boolean
):
Promise
<
void
>
;
openDefaultKeybindingsFile
():
Promise
<
IEditorPane
|
undefined
>
;
openDefaultKeybindingsFile
():
Promise
<
IEditorPane
|
undefined
>
;
configureSettingsForLanguage
(
language
:
string
|
null
):
void
;
}
}
export
function
getSettingsTargetName
(
target
:
ConfigurationTarget
,
resource
:
URI
,
workspaceContextService
:
IWorkspaceContextService
):
string
{
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录