Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
e69fb281
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,发现更多精彩内容 >>
提交
e69fb281
编写于
9月 14, 2016
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[html] update language server for document link support
上级
2a4e5b02
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
63 addition
and
57 deletion
+63
-57
extensions/html/package.json
extensions/html/package.json
+1
-1
extensions/html/server/package.json
extensions/html/server/package.json
+1
-1
extensions/html/server/src/htmlServerMain.ts
extensions/html/server/src/htmlServerMain.ts
+10
-1
extensions/html/server/src/service/htmlLanguageService.ts
extensions/html/server/src/service/htmlLanguageService.ts
+5
-21
extensions/html/server/src/service/services/htmlLinks.ts
extensions/html/server/src/service/services/htmlLinks.ts
+15
-11
extensions/html/server/src/service/test/completion.test.ts
extensions/html/server/src/service/test/completion.test.ts
+12
-18
extensions/html/server/src/service/test/highlighting.test.ts
extensions/html/server/src/service/test/highlighting.test.ts
+0
-1
extensions/html/server/src/service/test/links.test.ts
extensions/html/server/src/service/test/links.test.ts
+19
-3
未找到文件。
extensions/html/package.json
浏览文件 @
e69fb281
...
...
@@ -104,7 +104,7 @@
}
},
"dependencies"
:
{
"vscode-languageclient"
:
"^2.
4.2-next.22
"
,
"vscode-languageclient"
:
"^2.
6.0-next.1
"
,
"vscode-nls"
:
"^1.0.7"
}
}
extensions/html/server/package.json
浏览文件 @
e69fb281
...
...
@@ -8,7 +8,7 @@
"node"
:
"*"
},
"dependencies"
:
{
"vscode-languageserver"
:
"^2.
4.0-next.12
"
,
"vscode-languageserver"
:
"^2.
6.0-next.3
"
,
"vscode-nls"
:
"^1.0.4"
,
"vscode-uri"
:
"^0.0.7"
},
...
...
extensions/html/server/src/htmlServerMain.ts
浏览文件 @
e69fb281
...
...
@@ -27,10 +27,12 @@ let documents: TextDocuments = new TextDocuments();
// for open, change and close text document events
documents
.
listen
(
connection
);
let
workspacePath
:
string
;
// After the server has started the client sends an initilize request. The server receives
// in the passed params the rootPath of the workspace plus the client capabilites
connection
.
onInitialize
((
params
:
InitializeParams
):
InitializeResult
=>
{
workspacePath
=
params
.
rootPath
;
return
{
capabilities
:
{
// Tell the client that the server works in FULL text document sync mode
...
...
@@ -38,7 +40,8 @@ connection.onInitialize((params: InitializeParams): InitializeResult => {
completionProvider
:
{
resolveProvider
:
false
,
triggerCharacters
:
[
'
.
'
,
'
:
'
,
'
<
'
,
'
"
'
,
'
=
'
,
'
/
'
]
},
documentHighlightProvider
:
true
,
documentRangeFormattingProvider
:
true
,
documentFormattingProvider
:
true
documentFormattingProvider
:
true
,
documentLinkProvider
:
true
}
};
});
...
...
@@ -108,5 +111,11 @@ connection.onDocumentRangeFormatting(formatParams => {
return
languageService
.
format
(
document
,
formatParams
.
range
,
getFormattingOptions
(
formatParams
));
});
connection
.
onDocumentLinks
(
documentLinkParam
=>
{
let
document
=
documents
.
get
(
documentLinkParam
.
textDocument
.
uri
);
return
languageService
.
findDocumentLinks
(
document
,
workspacePath
);
});
// Listen on the connection
connection
.
listen
();
\ No newline at end of file
extensions/html/server/src/service/htmlLanguageService.ts
浏览文件 @
e69fb281
...
...
@@ -6,27 +6,11 @@
import
{
parse
}
from
'
./parser/htmlParser
'
;
import
{
doComplete
}
from
'
./services/htmlCompletion
'
;
import
{
format
}
from
'
./services/htmlFormatter
'
;
import
{
provide
Links
}
from
'
./services/htmlLinks
'
;
import
{
findDocument
Links
}
from
'
./services/htmlLinks
'
;
import
{
findDocumentHighlights
}
from
'
./services/htmlHighlighting
'
;
import
{
TextDocument
,
Position
,
CompletionItem
,
CompletionList
,
Hover
,
Range
,
SymbolInformation
,
Diagnostic
,
TextEdit
,
DocumentHighlight
,
FormattingOptions
,
MarkedString
}
from
'
vscode-languageserver-types
'
;
export
{
TextDocument
,
Position
,
CompletionItem
,
CompletionList
,
Hover
,
Range
,
SymbolInformation
,
Diagnostic
,
TextEdit
,
DocumentHighlight
,
FormattingOptions
,
MarkedString
};
export
class
DocumentLink
{
/**
* The range this link applies to.
*/
range
:
Range
;
/**
* The uri this link points to.
*/
target
:
string
;
}
import
{
TextDocument
,
Position
,
CompletionItem
,
CompletionList
,
Hover
,
Range
,
SymbolInformation
,
Diagnostic
,
TextEdit
,
DocumentHighlight
,
FormattingOptions
,
MarkedString
,
DocumentLink
}
from
'
vscode-languageserver-types
'
;
export
{
TextDocument
,
Position
,
CompletionItem
,
CompletionList
,
Hover
,
Range
,
SymbolInformation
,
Diagnostic
,
TextEdit
,
DocumentHighlight
,
FormattingOptions
,
MarkedString
,
DocumentLink
};
export
interface
HTMLFormatConfiguration
{
tabSize
:
number
;
...
...
@@ -52,7 +36,7 @@ export interface LanguageService {
findDocumentHighlights
(
document
:
TextDocument
,
position
:
Position
,
htmlDocument
:
HTMLDocument
):
DocumentHighlight
[];
doComplete
(
document
:
TextDocument
,
position
:
Position
,
htmlDocument
:
HTMLDocument
,
options
?:
CompletionConfiguration
):
CompletionList
;
format
(
document
:
TextDocument
,
range
:
Range
,
options
:
HTMLFormatConfiguration
):
TextEdit
[];
provide
Links
(
document
:
TextDocument
,
workspacePath
:
string
):
DocumentLink
[];
findDocument
Links
(
document
:
TextDocument
,
workspacePath
:
string
):
DocumentLink
[];
}
export
function
getLanguageService
()
:
LanguageService
{
...
...
@@ -61,6 +45,6 @@ export function getLanguageService() : LanguageService {
doComplete
,
format
,
findDocumentHighlights
,
provide
Links
findDocument
Links
};
}
\ No newline at end of file
extensions/html/server/src/service/services/htmlLinks.ts
浏览文件 @
e69fb281
...
...
@@ -12,15 +12,13 @@ import Uri from 'vscode-uri';
import
{
DocumentLink
}
from
'
../htmlLanguageService
'
;
function
_
stripQuotes
(
url
:
string
):
string
{
function
stripQuotes
(
url
:
string
):
string
{
return
url
.
replace
(
/^'
([^
'
]
+
)
'$/
,(
substr
,
match1
)
=>
match1
)
.
replace
(
/^"
([^
"
]
+
)
"$/
,(
substr
,
match1
)
=>
match1
);
}
export
function
_getWorkspaceUrl
(
modelAbsoluteUri
:
Uri
,
rootAbsoluteUrl
:
Uri
,
tokenContent
:
string
):
string
{
tokenContent
=
_stripQuotes
(
tokenContent
);
function
getWorkspaceUrl
(
modelAbsoluteUri
:
Uri
,
rootAbsoluteUrl
:
Uri
,
tokenContent
:
string
):
string
{
if
(
/^
\s
*javascript
\:
/i
.
test
(
tokenContent
)
||
/^
\s
*
\#
/i
.
test
(
tokenContent
))
{
return
null
;
}
...
...
@@ -64,9 +62,14 @@ export function _getWorkspaceUrl(modelAbsoluteUri: Uri, rootAbsoluteUrl: Uri, to
return
potentialResult
;
}
function
createLink
(
document
:
TextDocument
,
rootAbsoluteUrl
:
Uri
,
tokenContent
:
string
,
startOffset
:
number
,
endOffset
:
number
):
DocumentLink
{
function
createLink
(
document
:
TextDocument
,
rootAbsoluteUrl
:
Uri
,
attributeValue
:
string
,
startOffset
:
number
,
endOffset
:
number
):
DocumentLink
{
let
documentUri
=
Uri
.
parse
(
document
.
uri
);
let
workspaceUrl
=
_getWorkspaceUrl
(
documentUri
,
rootAbsoluteUrl
,
tokenContent
);
let
tokenContent
=
stripQuotes
(
attributeValue
);
if
(
tokenContent
.
length
<
attributeValue
.
length
)
{
startOffset
++
;
endOffset
--
;
}
let
workspaceUrl
=
getWorkspaceUrl
(
documentUri
,
rootAbsoluteUrl
,
tokenContent
);
if
(
!
workspaceUrl
)
{
return
null
;
}
...
...
@@ -76,7 +79,7 @@ function createLink(document: TextDocument, rootAbsoluteUrl: Uri, tokenContent:
};
}
export
function
provide
Links
(
document
:
TextDocument
,
workspacePath
:
string
):
DocumentLink
[]
{
export
function
findDocument
Links
(
document
:
TextDocument
,
workspacePath
:
string
):
DocumentLink
[]
{
let
newLinks
:
DocumentLink
[]
=
[];
let
rootAbsoluteUrl
:
Uri
=
null
;
...
...
@@ -94,13 +97,13 @@ export function provideLinks(document: TextDocument, workspacePath:string): Docu
while
(
token
!==
TokenType
.
EOS
)
{
switch
(
token
)
{
case
TokenType
.
AttributeName
:
let
tokenContent
=
scanner
.
getTokenText
();
afterHrefOrSrc
=
tokenContent
===
'
src
'
||
tokenContent
===
'
href
'
;
let
attributeName
=
scanner
.
getTokenText
();
afterHrefOrSrc
=
attributeName
===
'
src
'
||
attributeName
===
'
href
'
;
break
;
case
TokenType
.
AttributeValue
:
if
(
afterHrefOrSrc
)
{
let
tokenContent
=
scanner
.
getTokenText
();
let
link
=
createLink
(
document
,
rootAbsoluteUrl
,
tokenContent
,
scanner
.
getTokenOffset
(),
scanner
.
getTokenEnd
());
let
attributeValue
=
scanner
.
getTokenText
();
let
link
=
createLink
(
document
,
rootAbsoluteUrl
,
attributeValue
,
scanner
.
getTokenOffset
(),
scanner
.
getTokenEnd
());
if
(
link
)
{
newLinks
.
push
(
link
);
}
...
...
@@ -108,6 +111,7 @@ export function provideLinks(document: TextDocument, workspacePath:string): Docu
}
break
;
}
token
=
scanner
.
scan
();
}
return
newLinks
;
}
\ No newline at end of file
extensions/html/server/src/service/test/completion.test.ts
浏览文件 @
e69fb281
...
...
@@ -67,21 +67,16 @@ let testCompletionFor = function (value: string, expected: { count?: number, ite
let
document
=
TextDocument
.
create
(
'
test://test/test.html
'
,
'
html
'
,
0
,
value
);
let
position
=
document
.
positionAt
(
offset
);
let
htmlDoc
=
ls
.
parseHTMLDocument
(
document
);
return
asPromise
(
ls
.
doComplete
(
document
,
position
,
htmlDoc
,
settings
)).
then
(
list
=>
{
try
{
if
(
expected
.
count
)
{
assert
.
equal
(
list
.
items
,
expected
.
count
);
}
if
(
expected
.
items
)
{
for
(
let
item
of
expected
.
items
)
{
assertCompletion
(
list
,
item
,
document
,
offset
);
}
}
}
catch
(
e
)
{
return
Promise
.
reject
(
e
);
let
list
=
ls
.
doComplete
(
document
,
position
,
htmlDoc
,
settings
);
if
(
expected
.
count
)
{
assert
.
equal
(
list
.
items
,
expected
.
count
);
}
if
(
expected
.
items
)
{
for
(
let
item
of
expected
.
items
)
{
assertCompletion
(
list
,
item
,
document
,
offset
);
}
}
);
}
return
Promise
.
resolve
(
);
};
function
run
(
tests
:
Thenable
<
void
>
[],
testDone
)
{
Promise
.
all
(
tests
).
then
(()
=>
{
...
...
@@ -275,12 +270,11 @@ suite('HTML Completion', () => {
],
testDone
);
});
suite
(
'
Handlevar Completion
'
,
(
testDone
)
=>
{
test
(
'
Handlebar Completion
'
,
function
(
testDone
)
{
run
([
testCompletionFor
(
'
<script id="entry-template" type="text/x-handlebars-template"> | </script>
'
,
{
testCompletionFor
(
'
<script id="entry-template" type="text/x-handlebars-template"> <| </script>
'
,
{
items
:
[
{
label
:
'
div
'
,
resultText
:
'
<script id="entry-template" type="text/x-handlebars-template"> <div
></div>
</script>
'
},
{
label
:
'
div
'
,
resultText
:
'
<script id="entry-template" type="text/x-handlebars-template"> <div </script>
'
},
]
})
],
testDone
);
...
...
extensions/html/server/src/service/test/highlighting.test.ts
浏览文件 @
e69fb281
...
...
@@ -13,7 +13,6 @@ export function assertHighlights(value: string, expectedMatches: number[], eleme
value
=
value
.
substr
(
0
,
offset
)
+
value
.
substr
(
offset
+
1
);
let
document
=
TextDocument
.
create
(
'
test://test/test.html
'
,
'
html
'
,
0
,
value
);
let
htmlDocument
=
htmlLanguageService
.
getLanguageService
().
parseHTMLDocument
(
document
);
let
position
=
document
.
positionAt
(
offset
);
let
ls
=
htmlLanguageService
.
getLanguageService
();
...
...
extensions/html/server/src/service/test/links.test.ts
浏览文件 @
e69fb281
...
...
@@ -9,13 +9,23 @@ import * as assert from 'assert';
import
*
as
htmlLinks
from
'
../services/htmlLinks
'
;
import
{
CompletionList
,
TextDocument
,
TextEdit
,
Position
,
CompletionItemKind
}
from
'
vscode-languageserver-types
'
;
import
Uri
from
'
vscode-uri
'
;
import
*
as
htmlLanguageService
from
'
../htmlLanguageService
'
;
suite
(
'
HTML Link Detection
'
,
()
=>
{
function
testLinkCreation
(
modelUrl
:
string
,
rootUrl
:
string
,
tokenContent
:
string
,
expected
:
string
):
void
{
var
_modelUrl
=
Uri
.
parse
(
modelUrl
);
var
actual
=
htmlLinks
.
_getWorkspaceUrl
(
_modelUrl
,
Uri
.
parse
(
rootUrl
),
tokenContent
);
assert
.
equal
(
actual
,
expected
);
let
document
=
TextDocument
.
create
(
modelUrl
,
'
html
'
,
0
,
`<a href="
${
tokenContent
}
">`
);
let
ls
=
htmlLanguageService
.
getLanguageService
();
let
links
=
ls
.
findDocumentLinks
(
document
,
rootUrl
);
assert
.
equal
(
links
[
0
]
&&
links
[
0
].
target
,
expected
);
}
function
testLinkDetection
(
value
:
string
,
expectedLinkLocations
:
number
[]):
void
{
let
document
=
TextDocument
.
create
(
'
test://test/test.html
'
,
'
html
'
,
0
,
value
);
let
ls
=
htmlLanguageService
.
getLanguageService
();
let
links
=
ls
.
findDocumentLinks
(
document
,
'
test://test
'
);
assert
.
deepEqual
(
links
.
map
(
l
=>
l
.
range
.
start
.
character
),
expectedLinkLocations
);
}
test
(
'
Link creation
'
,
()
=>
{
...
...
@@ -68,4 +78,10 @@ suite('HTML Link Detection', () => {
// Bug #18314: Ctrl + Click does not open existing file if folder's name starts with 'c' character
testLinkCreation
(
'
file:///c:/Alex/working_dir/18314-link-detection/test.html
'
,
'
file:///c:/Alex/working_dir/18314-link-detection/
'
,
'
/class/class.js
'
,
'
file:///c:/Alex/working_dir/18314-link-detection/class/class.js
'
);
});
test
(
'
Link detection
'
,
()
=>
{
testLinkDetection
(
'
<img src="foo.png">
'
,
[
9
]);
testLinkDetection
(
'
<a href="http://server/foo.html">
'
,
[
8
]);
});
});
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录