Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
8d703ff0
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,发现更多精彩内容 >>
提交
8d703ff0
编写于
6月 14, 2016
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[css extension] cache stylesheets ASTs
上级
1fe6e953
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
104 addition
and
14 deletion
+104
-14
extensions/css/server/src/cssServerMain.ts
extensions/css/server/src/cssServerMain.ts
+20
-14
extensions/css/server/src/stylesheetCache.ts
extensions/css/server/src/stylesheetCache.ts
+84
-0
未找到文件。
extensions/css/server/src/cssServerMain.ts
浏览文件 @
8d703ff0
...
...
@@ -10,7 +10,7 @@ import {
}
from
'
vscode-languageserver
'
;
import
{
getCSSLanguageService
,
getSCSSLanguageService
,
getLESSLanguageService
,
LanguageSettings
,
LanguageService
}
from
'
./cssLanguageService
'
;
import
{
Stylesheet
}
from
'
./parser/cssNodes
'
;
import
{
getStylesheetCache
}
from
'
./stylesheetCache
'
;
import
*
as
nls
from
'
vscode-nls
'
;
nls
.
config
(
process
.
env
[
'
VSCODE_NLS_CONFIG
'
]);
...
...
@@ -29,6 +29,9 @@ export interface Settings {
// stdin / stdout for message passing
let
connection
:
IConnection
=
createConnection
(
new
IPCMessageReader
(
process
),
new
IPCMessageWriter
(
process
));
console
.
log
=
connection
.
console
.
log
.
bind
(
connection
.
console
);
console
.
error
=
connection
.
console
.
error
.
bind
(
connection
.
console
);
// Create a simple text document manager. The text document manager
// supports full document sync only
let
documents
:
TextDocuments
=
new
TextDocuments
();
...
...
@@ -36,6 +39,13 @@ let documents: TextDocuments = new TextDocuments();
// for open, change and close text document events
documents
.
listen
(
connection
);
let
stylesheets
=
getStylesheetCache
(
10
,
60
,
document
=>
getLanguageService
(
document
).
parseStylesheet
(
document
));
documents
.
onDidClose
(
e
=>
{
stylesheets
.
onDocumentRemoved
(
e
.
document
);
});
connection
.
onShutdown
(()
=>
{
stylesheets
.
dispose
();
});
// 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.
...
...
@@ -87,62 +97,58 @@ function updateConfiguration(settings: Settings) {
}
function
validateTextDocument
(
textDocument
:
TextDocument
):
void
{
let
stylesheet
=
getStylesheet
(
textDocument
);
let
stylesheet
=
stylesheets
.
getStylesheet
(
textDocument
);
getLanguageService
(
textDocument
).
doValidation
(
textDocument
,
stylesheet
).
then
(
diagnostics
=>
{
// Send the computed diagnostics to VSCode.
connection
.
sendDiagnostics
({
uri
:
textDocument
.
uri
,
diagnostics
});
});
}
function
getStylesheet
(
document
:
TextDocument
):
Stylesheet
{
return
getLanguageService
(
document
).
parseStylesheet
(
document
);
}
connection
.
onCompletion
(
textDocumentPosition
=>
{
let
document
=
documents
.
get
(
textDocumentPosition
.
textDocument
.
uri
);
let
stylesheet
=
getStylesheet
(
document
);
let
stylesheet
=
stylesheets
.
getStylesheet
(
document
);
return
getLanguageService
(
document
).
doComplete
(
document
,
textDocumentPosition
.
position
,
stylesheet
);
});
connection
.
onHover
(
textDocumentPosition
=>
{
let
document
=
documents
.
get
(
textDocumentPosition
.
textDocument
.
uri
);
let
styleSheet
=
getStylesheet
(
document
);
let
styleSheet
=
stylesheets
.
getStylesheet
(
document
);
return
getLanguageService
(
document
).
doHover
(
document
,
textDocumentPosition
.
position
,
styleSheet
);
});
connection
.
onDocumentSymbol
(
documentSymbolParams
=>
{
let
document
=
documents
.
get
(
documentSymbolParams
.
textDocument
.
uri
);
let
stylesheet
=
getStylesheet
(
document
);
let
stylesheet
=
stylesheets
.
getStylesheet
(
document
);
return
getLanguageService
(
document
).
findDocumentSymbols
(
document
,
stylesheet
);
});
connection
.
onDefinition
(
documentSymbolParams
=>
{
let
document
=
documents
.
get
(
documentSymbolParams
.
textDocument
.
uri
);
let
stylesheet
=
getStylesheet
(
document
);
let
stylesheet
=
stylesheets
.
getStylesheet
(
document
);
return
getLanguageService
(
document
).
findDefinition
(
document
,
documentSymbolParams
.
position
,
stylesheet
);
});
connection
.
onDocumentHighlight
(
documentSymbolParams
=>
{
let
document
=
documents
.
get
(
documentSymbolParams
.
textDocument
.
uri
);
let
stylesheet
=
getStylesheet
(
document
);
let
stylesheet
=
stylesheets
.
getStylesheet
(
document
);
return
getLanguageService
(
document
).
findDocumentHighlights
(
document
,
documentSymbolParams
.
position
,
stylesheet
);
});
connection
.
onReferences
(
referenceParams
=>
{
let
document
=
documents
.
get
(
referenceParams
.
textDocument
.
uri
);
let
stylesheet
=
getStylesheet
(
document
);
let
stylesheet
=
stylesheets
.
getStylesheet
(
document
);
return
getLanguageService
(
document
).
findReferences
(
document
,
referenceParams
.
position
,
stylesheet
);
});
connection
.
onCodeAction
(
codeActionParams
=>
{
let
document
=
documents
.
get
(
codeActionParams
.
textDocument
.
uri
);
let
stylesheet
=
getStylesheet
(
document
);
let
stylesheet
=
stylesheets
.
getStylesheet
(
document
);
return
getLanguageService
(
document
).
doCodeActions
(
document
,
codeActionParams
.
range
,
codeActionParams
.
context
,
stylesheet
);
});
connection
.
onRequest
(
ColorSymbolRequest
.
type
,
uri
=>
{
let
document
=
documents
.
get
(
uri
);
let
stylesheet
=
getStylesheet
(
document
);
let
stylesheet
=
stylesheets
.
getStylesheet
(
document
);
return
getLanguageService
(
document
).
findColorSymbols
(
document
,
stylesheet
);
});
...
...
extensions/css/server/src/stylesheetCache.ts
0 → 100644
浏览文件 @
8d703ff0
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
{
TextDocument
}
from
'
vscode-languageserver
'
;
import
{
Stylesheet
}
from
'
./parser/cssNodes
'
;
export
interface
StylesheetCache
{
getStylesheet
(
document
:
TextDocument
):
Stylesheet
;
onDocumentRemoved
(
document
:
TextDocument
):
void
;
dispose
():
void
;
}
export
function
getStylesheetCache
(
maxEntries
:
number
,
cleanupIntervalTimeInSec
:
number
,
parseStylesheet
:
(
document
:
TextDocument
)
=>
Stylesheet
)
:
StylesheetCache
{
let
styleSheets
:
{
[
uri
:
string
]:
{
version
:
number
,
languageId
:
string
,
cTime
:
number
,
stylesheet
:
Stylesheet
}}
=
{};
let
nStyleSheets
=
0
;
let
cleanupInterval
=
void
0
;
if
(
cleanupIntervalTimeInSec
>
0
)
{
cleanupInterval
=
setInterval
(()
=>
{
let
cutoffTime
=
Date
.
now
()
-
cleanupIntervalTimeInSec
*
1000
;
let
uris
=
Object
.
keys
(
styleSheets
);
for
(
let
uri
of
uris
)
{
let
stylesheetInfo
=
styleSheets
[
uri
];
if
(
stylesheetInfo
.
cTime
<
cutoffTime
)
{
delete
styleSheets
[
uri
];
nStyleSheets
--
;
}
}
},
cleanupIntervalTimeInSec
*
1000
);
}
return
{
getStylesheet
(
document
:
TextDocument
)
{
let
version
=
document
.
version
;
let
languageId
=
document
.
languageId
;
let
stylesheetInfo
=
styleSheets
[
document
.
uri
];
if
(
stylesheetInfo
&&
stylesheetInfo
.
version
===
version
&&
stylesheetInfo
.
languageId
===
languageId
)
{
stylesheetInfo
.
cTime
=
Date
.
now
();
return
stylesheetInfo
.
stylesheet
;
}
let
stylesheet
=
parseStylesheet
(
document
);
styleSheets
[
document
.
uri
]
=
{
stylesheet
,
version
,
languageId
,
cTime
:
Date
.
now
()};
if
(
!
stylesheetInfo
)
{
nStyleSheets
++
;
}
if
(
nStyleSheets
===
maxEntries
)
{
let
oldestTime
=
Number
.
MAX_VALUE
;
let
oldestUri
=
null
;
for
(
let
uri
in
styleSheets
)
{
let
stylesheetInfo
=
styleSheets
[
uri
];
if
(
stylesheetInfo
.
cTime
<
oldestTime
)
{
oldestUri
=
uri
;
oldestTime
=
stylesheetInfo
.
cTime
;
}
}
if
(
oldestUri
)
{
delete
styleSheets
[
oldestUri
];
nStyleSheets
--
;
}
}
return
stylesheet
;
},
onDocumentRemoved
(
document
:
TextDocument
)
{
let
uri
=
document
.
uri
;
if
(
styleSheets
[
uri
])
{
delete
styleSheets
[
uri
];
nStyleSheets
--
;
}
},
dispose
()
{
if
(
typeof
cleanupInterval
!==
'
undefined
'
)
{
clearInterval
(
cleanupInterval
);
cleanupInterval
=
void
0
;
styleSheets
=
{};
nStyleSheets
=
0
;
}
}
};
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录