Skip to content

Commit 12325a0

Browse files
authored
Implement support for css.customData (#44)
* Implement support for css.customData * comment * schema
1 parent bfe5350 commit 12325a0

9 files changed

Lines changed: 78 additions & 28 deletions

File tree

LSP-css.sublime-settings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// "colorProvider": true,
1010
},
1111
"initializationOptions": {
12+
"handledSchemas": ["file"],
1213
"provideFormatter": true,
1314
},
1415
"settings": {

language-server/compile-language-server.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ fi
4141
temp_zip="src-${ref}.zip"
4242
curl -L "${GITHUB_REPO_URL}/archive/${ref}.zip" -o "${temp_zip}"
4343
unzip -z "${temp_zip}" | tr -d '\r' > update-info.log
44-
unzip "${temp_zip}" && rm -f "${temp_zip}"
44+
unzip "${temp_zip}" # ignore errors as there are some special file names that cause them
45+
rm -f "${temp_zip}" || exit
4546
mv "${GITHUB_REPO_NAME}-"* "${GITHUB_REPO_NAME}"
4647

4748
popd || exit
@@ -56,7 +57,7 @@ pushd "${SRC_DIR}" || exit
5657
npm install
5758

5859
# @see https://github.com/microsoft/vscode/blob/main/extensions/package.json
59-
npm install -D typescript@^4.8.3
60+
npm install -D typescript@^4.8.4
6061

6162
popd || exit
6263

@@ -72,7 +73,6 @@ cat << EOF > tsconfig.mod.json
7273
{
7374
"extends": "./tsconfig.json",
7475
"compilerOptions": {
75-
"skipLibCheck": true,
7676
"outDir": "./out"
7777
},
7878
"include": [

language-server/css-language-features/server/out/cssServer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ function startServer(connection, runtime) {
182182
if (document) {
183183
await dataProvidersReady;
184184
const stylesheet = stylesheets.get(document);
185-
return getLanguageService(document).findDocumentSymbols(document, stylesheet);
185+
return getLanguageService(document).findDocumentSymbols2(document, stylesheet);
186186
}
187187
return [];
188188
}, [], `Error while computing document symbols for ${documentSymbolParams.textDocument.uri}`, token);

language-server/package-lock.json

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

language-server/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
"dependencies": {
1313
"vscode-css-languageservice": "^6.1.1",
1414
"vscode-languageserver": "^8.1.0-next.1",
15-
"vscode-uri": "^3.0.5"
15+
"vscode-uri": "^3.0.6"
1616
},
1717
"devDependencies": {
1818
"@types/mocha": "^9.1.1",
1919
"@types/node": "16.x",
20-
"typescript": "^4.8.3"
20+
"typescript": "^4.8.4"
2121
},
2222
"scripts": {
2323
"compile": "gulp compile-extension:css-language-features-server",

language-server/update-info.log

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Archive: src-main.zip
2-
da506e9b8d86a7265d53255ef8a8603d792d74f5
2+
3e407526a1e2ff22cacb69c7e353e81a12f41029

plugin.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
from LSP.plugin.core.typing import Tuple
2-
from lsp_utils import NpmClientHandler
3-
import os
1+
from .types import CustomDataChangedNotification
2+
from LSP.plugin import Session, filename_to_uri
3+
from LSP.plugin.core.typing import List
4+
from lsp_utils import ApiWrapperInterface, NpmClientHandler
5+
from os import path
46

57

68
def plugin_loaded():
@@ -14,7 +16,7 @@ def plugin_unloaded():
1416
class LspCssPlugin(NpmClientHandler):
1517
package_name = __package__
1618
server_directory = "language-server"
17-
server_binary_path = os.path.join(
19+
server_binary_path = path.join(
1820
server_directory,
1921
"css-language-features",
2022
"server",
@@ -24,6 +26,20 @@ class LspCssPlugin(NpmClientHandler):
2426
)
2527

2628
@classmethod
27-
def minimum_node_version(cls) -> Tuple[int, int, int]:
28-
# this should be aligned with VSCode's Nodejs version
29-
return (14, 0, 0)
29+
def required_node_version(cls) -> str:
30+
return '>=14'
31+
32+
def on_ready(self, api: ApiWrapperInterface) -> None:
33+
session = self.weaksession()
34+
if not session:
35+
return
36+
self.resolve_custom_data_paths(session)
37+
38+
def resolve_custom_data_paths(self, session: Session) -> None:
39+
custom_data_paths = session.config.settings.get('css.customData') # type: List[str]
40+
resolved_custom_data_paths = [] # type: List[str]
41+
for folder in session.get_workspace_folders():
42+
# Converting to URI as server can't handle reading the content if it's a file path.
43+
resolved_custom_data_paths.extend(
44+
[filename_to_uri(path.abspath(path.join(folder.path, p))) for p in custom_data_paths])
45+
session.send_notification(CustomDataChangedNotification.create(resolved_custom_data_paths))

sublime-package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,25 @@
1818
"definitions": {
1919
"PluginConfig": {
2020
"properties": {
21+
"initializationOptions": {
22+
"type": "object",
23+
"additionalProperties": false,
24+
"properties": {
25+
"handledSchemas": {
26+
"type": "array",
27+
"items": {
28+
"type": "string"
29+
},
30+
"default": ["file"],
31+
"markdownDescription": "Types of protocols that the server supports for URIs provided through `css.customData`."
32+
},
33+
"provideFormatter": {
34+
"type": "boolean",
35+
"default": true,
36+
"markdownDescription": "Whether server provides formatter capabilities."
37+
}
38+
},
39+
},
2140
"settings": {
2241
"additionalProperties": false,
2342
"properties": {

types.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from LSP.plugin import Notification
2+
from LSP.plugin.core.typing import List
3+
4+
5+
FilePath = str
6+
7+
8+
class CustomDataChangedNotification:
9+
Type = 'css/customDataChanged'
10+
Params = List[FilePath]
11+
12+
@classmethod
13+
def create(cls, params: Params) -> Notification:
14+
return Notification(cls.Type, [params])

0 commit comments

Comments
 (0)