Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
2eabbee4
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,发现更多精彩内容 >>
提交
2eabbee4
编写于
8月 03, 2018
作者:
M
mechatroner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add two alternative language-changing interface functions
上级
2582f425
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
76 addition
and
10 deletion
+76
-10
src/vs/editor/common/services/languagesRegistry.ts
src/vs/editor/common/services/languagesRegistry.ts
+4
-0
src/vs/editor/common/services/modeService.ts
src/vs/editor/common/services/modeService.ts
+1
-0
src/vs/editor/common/services/modeServiceImpl.ts
src/vs/editor/common/services/modeServiceImpl.ts
+9
-0
src/vs/vscode.d.ts
src/vs/vscode.d.ts
+18
-0
src/vs/workbench/api/electron-browser/mainThreadEditors.ts
src/vs/workbench/api/electron-browser/mainThreadEditors.ts
+11
-7
src/vs/workbench/api/electron-browser/mainThreadLanguages.ts
src/vs/workbench/api/electron-browser/mainThreadLanguages.ts
+17
-1
src/vs/workbench/api/node/extHost.api.impl.ts
src/vs/workbench/api/node/extHost.api.impl.ts
+3
-0
src/vs/workbench/api/node/extHost.protocol.ts
src/vs/workbench/api/node/extHost.protocol.ts
+2
-0
src/vs/workbench/api/node/extHostLanguages.ts
src/vs/workbench/api/node/extHostLanguages.ts
+4
-0
src/vs/workbench/api/node/extHostTextEditor.ts
src/vs/workbench/api/node/extHostTextEditor.ts
+6
-2
src/vs/workbench/test/electron-browser/api/extHostTextEditor.test.ts
...bench/test/electron-browser/api/extHostTextEditor.test.ts
+1
-0
未找到文件。
src/vs/editor/common/services/languagesRegistry.ts
浏览文件 @
2eabbee4
...
@@ -211,6 +211,10 @@ export class LanguagesRegistry {
...
@@ -211,6 +211,10 @@ export class LanguagesRegistry {
return
Object
.
keys
(
this
.
_nameMap
);
return
Object
.
keys
(
this
.
_nameMap
);
}
}
public
isRegisteredModeExact
(
modeId
:
string
):
boolean
{
return
hasOwnProperty
.
call
(
this
.
_languages
,
modeId
);
}
public
getLanguageName
(
modeId
:
string
):
string
{
public
getLanguageName
(
modeId
:
string
):
string
{
if
(
!
hasOwnProperty
.
call
(
this
.
_languages
,
modeId
))
{
if
(
!
hasOwnProperty
.
call
(
this
.
_languages
,
modeId
))
{
return
null
;
return
null
;
...
...
src/vs/editor/common/services/modeService.ts
浏览文件 @
2eabbee4
...
@@ -46,5 +46,6 @@ export interface IModeService {
...
@@ -46,5 +46,6 @@ export interface IModeService {
getMode
(
commaSeparatedMimetypesOrCommaSeparatedIds
:
string
):
IMode
;
getMode
(
commaSeparatedMimetypesOrCommaSeparatedIds
:
string
):
IMode
;
getOrCreateMode
(
commaSeparatedMimetypesOrCommaSeparatedIds
:
string
):
TPromise
<
IMode
>
;
getOrCreateMode
(
commaSeparatedMimetypesOrCommaSeparatedIds
:
string
):
TPromise
<
IMode
>
;
getOrCreateModeByLanguageName
(
languageName
:
string
):
TPromise
<
IMode
>
;
getOrCreateModeByLanguageName
(
languageName
:
string
):
TPromise
<
IMode
>
;
getOrCreateModeByLanguageId
(
modeId
:
string
):
TPromise
<
IMode
>
;
getOrCreateModeByFilenameOrFirstLine
(
filename
:
string
,
firstLine
?:
string
):
TPromise
<
IMode
>
;
getOrCreateModeByFilenameOrFirstLine
(
filename
:
string
,
firstLine
?:
string
):
TPromise
<
IMode
>
;
}
}
src/vs/editor/common/services/modeServiceImpl.ts
浏览文件 @
2eabbee4
...
@@ -132,6 +132,15 @@ export class ModeServiceImpl implements IModeService {
...
@@ -132,6 +132,15 @@ export class ModeServiceImpl implements IModeService {
});
});
}
}
public
getOrCreateModeByLanguageId
(
modeId
:
string
):
TPromise
<
IMode
>
{
return
this
.
_onReady
().
then
(()
=>
{
if
(
!
this
.
_registry
.
isRegisteredModeExact
(
modeId
))
{
modeId
=
'
plaintext
'
;
}
return
this
.
_getOrCreateMode
(
modeId
);
});
}
private
_getModeIdByLanguageName
(
languageName
:
string
):
string
{
private
_getModeIdByLanguageName
(
languageName
:
string
):
string
{
const
modeIds
=
this
.
_registry
.
getModeIdsFromLanguageName
(
languageName
);
const
modeIds
=
this
.
_registry
.
getModeIdsFromLanguageName
(
languageName
);
...
...
src/vs/vscode.d.ts
浏览文件 @
2eabbee4
...
@@ -1119,6 +1119,21 @@ declare module 'vscode' {
...
@@ -1119,6 +1119,21 @@ declare module 'vscode' {
*/
*/
edit
(
callback
:
(
editBuilder
:
TextEditorEdit
)
=>
void
,
options
?:
{
undoStopBefore
:
boolean
;
undoStopAfter
:
boolean
;
}):
Thenable
<
boolean
>
;
edit
(
callback
:
(
editBuilder
:
TextEditorEdit
)
=>
void
,
options
?:
{
undoStopBefore
:
boolean
;
undoStopAfter
:
boolean
;
}):
Thenable
<
boolean
>
;
/**
* Change document language by Id
*
* @param languageId new language identifier
*/
setLanguageById
(
languageId
:
string
):
void
;
/**
* Change document language by Name
*
* @param languageName new language name
*/
setLanguageByName
(
languageName
:
string
):
void
;
/**
/**
* Insert a [snippet](#SnippetString) and put the editor into snippet mode. "Snippet mode"
* Insert a [snippet](#SnippetString) and put the editor into snippet mode. "Snippet mode"
* means the editor adds placeholders and additional cursors so that the user can complete
* means the editor adds placeholders and additional cursors so that the user can complete
...
@@ -1141,6 +1156,7 @@ declare module 'vscode' {
...
@@ -1141,6 +1156,7 @@ declare module 'vscode' {
* @param decorationType A decoration type.
* @param decorationType A decoration type.
* @param rangesOrOptions Either [ranges](#Range) or more detailed [options](#DecorationOptions).
* @param rangesOrOptions Either [ranges](#Range) or more detailed [options](#DecorationOptions).
*/
*/
setDecorations
(
decorationType
:
TextEditorDecorationType
,
rangesOrOptions
:
Range
[]
|
DecorationOptions
[]):
void
;
setDecorations
(
decorationType
:
TextEditorDecorationType
,
rangesOrOptions
:
Range
[]
|
DecorationOptions
[]):
void
;
/**
/**
...
@@ -7375,6 +7391,8 @@ declare module 'vscode' {
...
@@ -7375,6 +7391,8 @@ declare module 'vscode' {
*/
*/
export
namespace
languages
{
export
namespace
languages
{
export
function
setLanguageById
(
documentUri
:
Uri
,
languageId
:
string
):
Thenable
<
void
>
;
/**
/**
* Return the identifiers of all known languages.
* Return the identifiers of all known languages.
* @return Promise resolving to an array of identifier strings.
* @return Promise resolving to an array of identifier strings.
...
...
src/vs/workbench/api/electron-browser/mainThreadEditors.ts
浏览文件 @
2eabbee4
...
@@ -179,14 +179,18 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
...
@@ -179,14 +179,18 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
if
(
!
mainThreadEditor
)
{
if
(
!
mainThreadEditor
)
{
return
TPromise
.
wrapError
(
disposed
(
`TextEditor(
${
id
}
)`
));
return
TPromise
.
wrapError
(
disposed
(
`TextEditor(
${
id
}
)`
));
}
}
let
textModel
=
mainThreadEditor
.
getModel
();
let
mode
=
this
.
_modeService
.
getOrCreateModeByLanguageId
(
languageId
);
let
modelService
=
this
.
_modelService
;
this
.
_modelService
.
setMode
(
mainThreadEditor
.
getModel
(),
mode
);
let
modeService
=
this
.
_modeService
;
return
TPromise
.
as
(
null
);
if
(
!
modelService
||
!
modeService
)
{
}
return
TPromise
.
wrapError
(
new
Error
(
'
modeService is null for some unit tests
'
));
$trySetLanguageByName
(
id
:
string
,
languageName
:
string
):
TPromise
<
void
>
{
let
mainThreadEditor
=
this
.
_documentsAndEditors
.
getEditor
(
id
);
if
(
!
mainThreadEditor
)
{
return
TPromise
.
wrapError
(
disposed
(
`TextEditor(
${
id
}
)`
));
}
}
let
mode
=
modeService
.
getOrCreateModeByLanguageName
(
languageId
);
let
mode
=
this
.
_modeService
.
getOrCreateModeByLanguageName
(
languageName
);
modelService
.
setMode
(
textModel
,
mode
);
this
.
_modelService
.
setMode
(
mainThreadEditor
.
getModel
()
,
mode
);
return
TPromise
.
as
(
null
);
return
TPromise
.
as
(
null
);
}
}
...
...
src/vs/workbench/api/electron-browser/mainThreadLanguages.ts
浏览文件 @
2eabbee4
...
@@ -5,7 +5,9 @@
...
@@ -5,7 +5,9 @@
'
use strict
'
;
'
use strict
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
URI
,
{
UriComponents
}
from
'
vs/base/common/uri
'
;
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
import
{
IModeService
}
from
'
vs/editor/common/services/modeService
'
;
import
{
IModelService
}
from
'
vs/editor/common/services/modelService
'
;
import
{
MainThreadLanguagesShape
,
MainContext
,
IExtHostContext
}
from
'
../node/extHost.protocol
'
;
import
{
MainThreadLanguagesShape
,
MainContext
,
IExtHostContext
}
from
'
../node/extHost.protocol
'
;
import
{
extHostNamedCustomer
}
from
'
vs/workbench/api/electron-browser/extHostCustomers
'
;
import
{
extHostNamedCustomer
}
from
'
vs/workbench/api/electron-browser/extHostCustomers
'
;
...
@@ -13,12 +15,15 @@ import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostC
...
@@ -13,12 +15,15 @@ import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostC
export
class
MainThreadLanguages
implements
MainThreadLanguagesShape
{
export
class
MainThreadLanguages
implements
MainThreadLanguagesShape
{
private
_modeService
:
IModeService
;
private
_modeService
:
IModeService
;
private
_modelService
:
IModelService
;
constructor
(
constructor
(
extHostContext
:
IExtHostContext
,
extHostContext
:
IExtHostContext
,
@
IModeService
modeService
:
IModeService
@
IModeService
modeService
:
IModeService
,
@
IModelService
modelService
:
IModelService
)
{
)
{
this
.
_modeService
=
modeService
;
this
.
_modeService
=
modeService
;
this
.
_modelService
=
modelService
;
}
}
public
dispose
():
void
{
public
dispose
():
void
{
...
@@ -27,4 +32,15 @@ export class MainThreadLanguages implements MainThreadLanguagesShape {
...
@@ -27,4 +32,15 @@ export class MainThreadLanguages implements MainThreadLanguagesShape {
$getLanguages
():
TPromise
<
string
[]
>
{
$getLanguages
():
TPromise
<
string
[]
>
{
return
TPromise
.
as
(
this
.
_modeService
.
getRegisteredModes
());
return
TPromise
.
as
(
this
.
_modeService
.
getRegisteredModes
());
}
}
$setLanguageById
(
resource
:
UriComponents
,
languageId
:
string
):
TPromise
<
void
>
{
const
uri
=
URI
.
revive
(
resource
);
let
model
=
this
.
_modelService
.
getModel
(
uri
);
if
(
!
model
)
{
return
TPromise
.
wrapError
(
new
Error
(
'
Invalid uri
'
));
}
let
mode
=
this
.
_modeService
.
getOrCreateModeByLanguageId
(
languageId
);
this
.
_modelService
.
setMode
(
model
,
mode
);
return
TPromise
.
as
(
null
);
}
}
}
src/vs/workbench/api/node/extHost.api.impl.ts
浏览文件 @
2eabbee4
...
@@ -258,6 +258,9 @@ export function createApiFactory(
...
@@ -258,6 +258,9 @@ export function createApiFactory(
getLanguages
():
TPromise
<
string
[]
>
{
getLanguages
():
TPromise
<
string
[]
>
{
return
extHostLanguages
.
getLanguages
();
return
extHostLanguages
.
getLanguages
();
},
},
setLanguageById
(
documentUri
:
vscode
.
Uri
,
languageId
:
string
):
TPromise
<
void
>
{
return
extHostLanguages
.
setLanguageById
(
documentUri
,
languageId
);
},
match
(
selector
:
vscode
.
DocumentSelector
,
document
:
vscode
.
TextDocument
):
number
{
match
(
selector
:
vscode
.
DocumentSelector
,
document
:
vscode
.
TextDocument
):
number
{
return
score
(
typeConverters
.
LanguageSelector
.
from
(
selector
),
document
.
uri
,
document
.
languageId
,
true
);
return
score
(
typeConverters
.
LanguageSelector
.
from
(
selector
),
document
.
uri
,
document
.
languageId
,
true
);
},
},
...
...
src/vs/workbench/api/node/extHost.protocol.ts
浏览文件 @
2eabbee4
...
@@ -194,6 +194,7 @@ export interface MainThreadTextEditorsShape extends IDisposable {
...
@@ -194,6 +194,7 @@ export interface MainThreadTextEditorsShape extends IDisposable {
$tryHideEditor
(
id
:
string
):
TPromise
<
void
>
;
$tryHideEditor
(
id
:
string
):
TPromise
<
void
>
;
$trySetOptions
(
id
:
string
,
options
:
ITextEditorConfigurationUpdate
):
TPromise
<
void
>
;
$trySetOptions
(
id
:
string
,
options
:
ITextEditorConfigurationUpdate
):
TPromise
<
void
>
;
$trySetLanguageById
(
id
:
string
,
languageId
:
string
):
TPromise
<
void
>
;
$trySetLanguageById
(
id
:
string
,
languageId
:
string
):
TPromise
<
void
>
;
$trySetLanguageByName
(
id
:
string
,
languageName
:
string
):
TPromise
<
void
>
;
$trySetDecorations
(
id
:
string
,
key
:
string
,
ranges
:
editorCommon
.
IDecorationOptions
[]):
TPromise
<
void
>
;
$trySetDecorations
(
id
:
string
,
key
:
string
,
ranges
:
editorCommon
.
IDecorationOptions
[]):
TPromise
<
void
>
;
$trySetDecorationsFast
(
id
:
string
,
key
:
string
,
ranges
:
number
[]):
TPromise
<
void
>
;
$trySetDecorationsFast
(
id
:
string
,
key
:
string
,
ranges
:
number
[]):
TPromise
<
void
>
;
$tryRevealRange
(
id
:
string
,
range
:
IRange
,
revealType
:
TextEditorRevealType
):
TPromise
<
void
>
;
$tryRevealRange
(
id
:
string
,
range
:
IRange
,
revealType
:
TextEditorRevealType
):
TPromise
<
void
>
;
...
@@ -288,6 +289,7 @@ export interface MainThreadLanguageFeaturesShape extends IDisposable {
...
@@ -288,6 +289,7 @@ export interface MainThreadLanguageFeaturesShape extends IDisposable {
export
interface
MainThreadLanguagesShape
extends
IDisposable
{
export
interface
MainThreadLanguagesShape
extends
IDisposable
{
$getLanguages
():
TPromise
<
string
[]
>
;
$getLanguages
():
TPromise
<
string
[]
>
;
$setLanguageById
(
resource
:
UriComponents
,
languageId
:
string
):
TPromise
<
void
>
;
}
}
export
interface
MainThreadMessageOptions
{
export
interface
MainThreadMessageOptions
{
...
...
src/vs/workbench/api/node/extHostLanguages.ts
浏览文件 @
2eabbee4
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
MainContext
,
MainThreadLanguagesShape
,
IMainContext
}
from
'
./extHost.protocol
'
;
import
{
MainContext
,
MainThreadLanguagesShape
,
IMainContext
}
from
'
./extHost.protocol
'
;
import
*
as
vscode
from
'
vscode
'
;
export
class
ExtHostLanguages
{
export
class
ExtHostLanguages
{
...
@@ -20,4 +21,7 @@ export class ExtHostLanguages {
...
@@ -20,4 +21,7 @@ export class ExtHostLanguages {
getLanguages
():
TPromise
<
string
[]
>
{
getLanguages
():
TPromise
<
string
[]
>
{
return
this
.
_proxy
.
$getLanguages
();
return
this
.
_proxy
.
$getLanguages
();
}
}
setLanguageById
(
documentUri
:
vscode
.
Uri
,
languageId
:
string
):
TPromise
<
void
>
{
return
this
.
_proxy
.
$setLanguageById
(
documentUri
,
languageId
);
}
}
}
src/vs/workbench/api/node/extHostTextEditor.ts
浏览文件 @
2eabbee4
...
@@ -435,8 +435,12 @@ export class ExtHostTextEditor implements vscode.TextEditor {
...
@@ -435,8 +435,12 @@ export class ExtHostTextEditor implements vscode.TextEditor {
this
.
_trySetSelection
();
this
.
_trySetSelection
();
}
}
setLanguageById
(
language_id
:
string
):
void
{
setLanguageById
(
languageId
:
string
):
void
{
this
.
_runOnProxy
(()
=>
this
.
_proxy
.
$trySetLanguageById
(
this
.
_id
,
language_id
));
this
.
_runOnProxy
(()
=>
this
.
_proxy
.
$trySetLanguageById
(
this
.
_id
,
languageId
));
}
setLanguageByName
(
languageName
:
string
):
void
{
this
.
_runOnProxy
(()
=>
this
.
_proxy
.
$trySetLanguageByName
(
this
.
_id
,
languageName
));
}
}
setDecorations
(
decorationType
:
vscode
.
TextEditorDecorationType
,
ranges
:
Range
[]
|
vscode
.
DecorationOptions
[]):
void
{
setDecorations
(
decorationType
:
vscode
.
TextEditorDecorationType
,
ranges
:
Range
[]
|
vscode
.
DecorationOptions
[]):
void
{
...
...
src/vs/workbench/test/electron-browser/api/extHostTextEditor.test.ts
浏览文件 @
2eabbee4
...
@@ -61,6 +61,7 @@ suite('ExtHostTextEditorOptions', () => {
...
@@ -61,6 +61,7 @@ suite('ExtHostTextEditorOptions', () => {
$tryShowEditor
:
undefined
,
$tryShowEditor
:
undefined
,
$tryHideEditor
:
undefined
,
$tryHideEditor
:
undefined
,
$trySetLanguageById
:
undefined
,
$trySetLanguageById
:
undefined
,
$trySetLanguageByName
:
undefined
,
$trySetDecorations
:
undefined
,
$trySetDecorations
:
undefined
,
$trySetDecorationsFast
:
undefined
,
$trySetDecorationsFast
:
undefined
,
$tryRevealRange
:
undefined
,
$tryRevealRange
:
undefined
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录