Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
bf3cfd9d
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,发现更多精彩内容 >>
提交
bf3cfd9d
编写于
2月 06, 2017
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Format Document Completely breaks code!!!. Fixes #19813
上级
63a69695
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
122 addition
and
13 deletion
+122
-13
extensions/html/server/src/modes/javascriptMode.ts
extensions/html/server/src/modes/javascriptMode.ts
+18
-11
extensions/html/server/src/test/fixtures/expected/19813-4spaces.html
...html/server/src/test/fixtures/expected/19813-4spaces.html
+22
-0
extensions/html/server/src/test/fixtures/expected/19813-tab.html
...ons/html/server/src/test/fixtures/expected/19813-tab.html
+22
-0
extensions/html/server/src/test/fixtures/expected/19813.html
extensions/html/server/src/test/fixtures/expected/19813.html
+22
-0
extensions/html/server/src/test/fixtures/inputs/19813.html
extensions/html/server/src/test/fixtures/inputs/19813.html
+19
-0
extensions/html/server/src/test/formatting.test.ts
extensions/html/server/src/test/formatting.test.ts
+19
-2
未找到文件。
extensions/html/server/src/modes/javascriptMode.ts
浏览文件 @
bf3cfd9d
...
...
@@ -23,12 +23,19 @@ export function getJavascriptMode(documentRegions: LanguageModelCache<HTMLDocume
let
compilerOptions
:
ts
.
CompilerOptions
=
{
allowNonTsExtensions
:
true
,
allowJs
:
true
,
target
:
ts
.
ScriptTarget
.
Latest
,
moduleResolution
:
ts
.
ModuleResolutionKind
.
Classic
};
let
currentTextDocument
:
TextDocument
;
let
scriptFileVersion
:
number
=
0
;
function
updateCurrentTextDocument
(
doc
:
TextDocument
)
{
if
(
!
currentTextDocument
||
doc
.
uri
!==
currentTextDocument
.
uri
||
doc
.
version
!==
currentTextDocument
.
version
)
{
currentTextDocument
=
jsDocuments
.
get
(
doc
);
scriptFileVersion
++
;
}
}
let
host
=
{
getCompilationSettings
:
()
=>
compilerOptions
,
getScriptFileNames
:
()
=>
[
FILE_NAME
,
JQUERY_D_TS
],
getScriptVersion
:
(
fileName
:
string
)
=>
{
if
(
fileName
===
FILE_NAME
)
{
return
String
(
currentTextDocument
.
v
ersion
);
return
String
(
scriptFileV
ersion
);
}
return
'
1
'
;
// default lib an jquery.d.ts are static
},
...
...
@@ -62,7 +69,7 @@ export function getJavascriptMode(documentRegions: LanguageModelCache<HTMLDocume
settings
=
options
&&
options
.
javascript
;
},
doValidation
(
document
:
TextDocument
):
Diagnostic
[]
{
currentTextDocument
=
jsDocuments
.
ge
t
(
document
);
updateCurrentTextDocumen
t
(
document
);
const
diagnostics
=
jsLanguageService
.
getSyntacticDiagnostics
(
FILE_NAME
);
return
diagnostics
.
map
((
diag
):
Diagnostic
=>
{
return
{
...
...
@@ -73,7 +80,7 @@ export function getJavascriptMode(documentRegions: LanguageModelCache<HTMLDocume
});
},
doComplete
(
document
:
TextDocument
,
position
:
Position
):
CompletionList
{
currentTextDocument
=
jsDocuments
.
ge
t
(
document
);
updateCurrentTextDocumen
t
(
document
);
let
offset
=
currentTextDocument
.
offsetAt
(
position
);
let
completions
=
jsLanguageService
.
getCompletionsAtPosition
(
FILE_NAME
,
offset
);
if
(
!
completions
)
{
...
...
@@ -100,7 +107,7 @@ export function getJavascriptMode(documentRegions: LanguageModelCache<HTMLDocume
};
},
doResolve
(
document
:
TextDocument
,
item
:
CompletionItem
):
CompletionItem
{
currentTextDocument
=
jsDocuments
.
ge
t
(
document
);
updateCurrentTextDocumen
t
(
document
);
let
details
=
jsLanguageService
.
getCompletionEntryDetails
(
FILE_NAME
,
item
.
data
.
offset
,
item
.
label
);
if
(
details
)
{
item
.
detail
=
ts
.
displayPartsToString
(
details
.
displayParts
);
...
...
@@ -110,7 +117,7 @@ export function getJavascriptMode(documentRegions: LanguageModelCache<HTMLDocume
return
item
;
},
doHover
(
document
:
TextDocument
,
position
:
Position
):
Hover
{
currentTextDocument
=
jsDocuments
.
ge
t
(
document
);
updateCurrentTextDocumen
t
(
document
);
let
info
=
jsLanguageService
.
getQuickInfoAtPosition
(
FILE_NAME
,
currentTextDocument
.
offsetAt
(
position
));
if
(
info
)
{
let
contents
=
ts
.
displayPartsToString
(
info
.
displayParts
);
...
...
@@ -122,7 +129,7 @@ export function getJavascriptMode(documentRegions: LanguageModelCache<HTMLDocume
return
null
;
},
doSignatureHelp
(
document
:
TextDocument
,
position
:
Position
):
SignatureHelp
{
currentTextDocument
=
jsDocuments
.
ge
t
(
document
);
updateCurrentTextDocumen
t
(
document
);
let
signHelp
=
jsLanguageService
.
getSignatureHelpItems
(
FILE_NAME
,
currentTextDocument
.
offsetAt
(
position
));
if
(
signHelp
)
{
let
ret
:
SignatureHelp
=
{
...
...
@@ -159,7 +166,7 @@ export function getJavascriptMode(documentRegions: LanguageModelCache<HTMLDocume
return
null
;
},
findDocumentHighlight
(
document
:
TextDocument
,
position
:
Position
):
DocumentHighlight
[]
{
currentTextDocument
=
jsDocuments
.
ge
t
(
document
);
updateCurrentTextDocumen
t
(
document
);
let
occurrences
=
jsLanguageService
.
getOccurrencesAtPosition
(
FILE_NAME
,
currentTextDocument
.
offsetAt
(
position
));
if
(
occurrences
)
{
return
occurrences
.
map
(
entry
=>
{
...
...
@@ -172,7 +179,7 @@ export function getJavascriptMode(documentRegions: LanguageModelCache<HTMLDocume
return
null
;
},
findDocumentSymbols
(
document
:
TextDocument
):
SymbolInformation
[]
{
currentTextDocument
=
jsDocuments
.
ge
t
(
document
);
updateCurrentTextDocumen
t
(
document
);
let
items
=
jsLanguageService
.
getNavigationBarItems
(
FILE_NAME
);
if
(
items
)
{
let
result
:
SymbolInformation
[]
=
[];
...
...
@@ -208,7 +215,7 @@ export function getJavascriptMode(documentRegions: LanguageModelCache<HTMLDocume
return
null
;
},
findDefinition
(
document
:
TextDocument
,
position
:
Position
):
Definition
{
currentTextDocument
=
jsDocuments
.
ge
t
(
document
);
updateCurrentTextDocumen
t
(
document
);
let
definition
=
jsLanguageService
.
getDefinitionAtPosition
(
FILE_NAME
,
currentTextDocument
.
offsetAt
(
position
));
if
(
definition
)
{
return
definition
.
filter
(
d
=>
d
.
fileName
===
FILE_NAME
).
map
(
d
=>
{
...
...
@@ -221,7 +228,7 @@ export function getJavascriptMode(documentRegions: LanguageModelCache<HTMLDocume
return
null
;
},
findReferences
(
document
:
TextDocument
,
position
:
Position
):
Location
[]
{
currentTextDocument
=
jsDocuments
.
ge
t
(
document
);
updateCurrentTextDocumen
t
(
document
);
let
references
=
jsLanguageService
.
getReferencesAtPosition
(
FILE_NAME
,
currentTextDocument
.
offsetAt
(
position
));
if
(
references
)
{
return
references
.
filter
(
d
=>
d
.
fileName
===
FILE_NAME
).
map
(
d
=>
{
...
...
@@ -234,7 +241,7 @@ export function getJavascriptMode(documentRegions: LanguageModelCache<HTMLDocume
return
null
;
},
format
(
document
:
TextDocument
,
range
:
Range
,
formatParams
:
FormattingOptions
):
TextEdit
[]
{
currentTextDocument
=
jsDocuments
.
ge
t
(
document
);
updateCurrentTextDocumen
t
(
document
);
let
initialIndentLevel
=
computeInitialIndent
(
document
,
range
,
formatParams
);
let
formatSettings
=
convertOptions
(
formatParams
,
settings
&&
settings
.
format
,
initialIndentLevel
+
1
);
let
start
=
currentTextDocument
.
offsetAt
(
range
.
start
);
...
...
extensions/html/server/src/test/fixtures/expected/19813-4spaces.html
0 → 100644
浏览文件 @
bf3cfd9d
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"utf-8"
>
<script>
Polymer
({
is
:
"
chat-messages
"
,
properties
:
{
user
:
{},
friend
:
{
observer
:
"
_friendChanged
"
}
},
});
</script>
</head>
<body>
</body>
</html>
\ No newline at end of file
extensions/html/server/src/test/fixtures/expected/19813-tab.html
0 → 100644
浏览文件 @
bf3cfd9d
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"utf-8"
>
<script>
Polymer
({
is
:
"
chat-messages
"
,
properties
:
{
user
:
{},
friend
:
{
observer
:
"
_friendChanged
"
}
},
});
</script>
</head>
<body>
</body>
</html>
\ No newline at end of file
extensions/html/server/src/test/fixtures/expected/19813.html
0 → 100644
浏览文件 @
bf3cfd9d
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"utf-8"
>
<script>
Polymer
({
is
:
"
chat-messages
"
,
properties
:
{
user
:
{},
friend
:
{
observer
:
"
_friendChanged
"
}
},
});
</script>
</head>
<body>
</body>
</html>
\ No newline at end of file
extensions/html/server/src/test/fixtures/inputs/19813.html
0 → 100644
浏览文件 @
bf3cfd9d
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"utf-8"
>
<script>
Polymer
({
is
:
"
chat-messages
"
,
properties
:
{
user
:
{},
friend
:
{
observer
:
"
_friendChanged
"
}
},
});
</script>
</head>
<body>
</body>
</html>
\ No newline at end of file
extensions/html/server/src/test/formatting.test.ts
浏览文件 @
bf3cfd9d
...
...
@@ -4,6 +4,9 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
*
as
path
from
'
path
'
import
*
as
fs
from
'
fs
'
import
*
as
assert
from
'
assert
'
;
import
{
getLanguageModes
}
from
'
../modes/languageModes
'
;
import
{
TextDocument
,
Range
,
TextEdit
,
FormattingOptions
}
from
'
vscode-languageserver-types
'
;
...
...
@@ -12,7 +15,7 @@ import { format } from '../modes/formatting';
suite
(
'
HTML Embedded Formatting
'
,
()
=>
{
function
assertFormat
(
value
:
string
,
expected
:
string
,
options
?:
any
):
void
{
function
assertFormat
(
value
:
string
,
expected
:
string
,
options
?:
any
,
formatOptions
?:
FormattingOptions
):
void
{
var
languageModes
=
getLanguageModes
({
css
:
true
,
javascript
:
true
});
if
(
options
)
{
languageModes
.
getAllModes
().
forEach
(
m
=>
m
.
configure
(
options
));
...
...
@@ -31,7 +34,9 @@ suite('HTML Embedded Formatting', () => {
}
let
document
=
TextDocument
.
create
(
'
test://test/test.html
'
,
'
html
'
,
0
,
value
);
let
range
=
Range
.
create
(
document
.
positionAt
(
rangeStartOffset
),
document
.
positionAt
(
rangeEndOffset
));
let
formatOptions
=
FormattingOptions
.
create
(
2
,
true
);
if
(
!
formatOptions
)
{
formatOptions
=
FormattingOptions
.
create
(
2
,
true
);
}
let
result
=
format
(
languageModes
,
document
,
range
,
formatOptions
,
{
css
:
true
,
javascript
:
true
});
...
...
@@ -39,6 +44,12 @@ suite('HTML Embedded Formatting', () => {
assert
.
equal
(
actual
,
expected
);
}
function
assertFormatWithFixture
(
fixtureName
:
string
,
expectedPath
:
string
,
options
?:
any
,
formatOptions
?:
FormattingOptions
):
void
{
let
input
=
fs
.
readFileSync
(
path
.
join
(
__dirname
,
'
fixtures
'
,
'
inputs
'
,
fixtureName
)).
toString
();
let
expected
=
fs
.
readFileSync
(
path
.
join
(
__dirname
,
'
fixtures
'
,
'
expected
'
,
expectedPath
)).
toString
();
assertFormat
(
input
,
expected
,
options
,
formatOptions
);
}
test
(
'
HTML only
'
,
function
():
any
{
assertFormat
(
'
<html><body><p>Hello</p></body></html>
'
,
'
<html>
\n\n
<body>
\n
<p>Hello</p>
\n
</body>
\n\n
</html>
'
);
assertFormat
(
'
|<html><body><p>Hello</p></body></html>|
'
,
'
<html>
\n\n
<body>
\n
<p>Hello</p>
\n
</body>
\n\n
</html>
'
);
...
...
@@ -56,6 +67,12 @@ suite('HTML Embedded Formatting', () => {
assertFormat
(
'
<html><head>
\n
<script>
\n
|var x=6;|
\n
</script></head></html>
'
,
'
<html><head>
\n
<script>
\n
var x = 6;
\n
</script></head></html>
'
);
});
test
(
'
HTLM & Scripts - Fixtures
'
,
function
()
{
assertFormatWithFixture
(
'
19813.html
'
,
'
19813.html
'
);
assertFormatWithFixture
(
'
19813.html
'
,
'
19813-4spaces.html
'
,
void
0
,
FormattingOptions
.
create
(
4
,
true
));
assertFormatWithFixture
(
'
19813.html
'
,
'
19813-tab.html
'
,
void
0
,
FormattingOptions
.
create
(
1
,
false
));
})
test
(
'
Script end tag
'
,
function
():
any
{
assertFormat
(
'
<html>
\n
<head>
\n
<script>
\n
var x = 0;
\n
</script></head></html>
'
,
'
<html>
\n\n
<head>
\n
<script>
\n
var x = 0;
\n\n
</script>
\n
</head>
\n\n
</html>
'
);
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录