Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: choose lanugage id based on extension when using css lsp #754

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions core/lspserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import subprocess
import threading
import traceback
import copy
from subprocess import PIPE
from sys import stderr
from typing import TYPE_CHECKING, Dict
Expand Down Expand Up @@ -391,6 +392,16 @@ def parse_document_uri(self, filepath, external_file_link):
return uri

def send_did_open_notification(self, fa: "FileAction"):
# vscode-css-language-server uses languageId to initialize from different entry points
if self.server_info["name"] == "vscode-css-language-server":
_, extension = os.path.splitext(fa.filepath)
if extension == ".less":
self.server_info["languageId"] = "less"
elif extension == ".scss" or extension == ".sass":
self.server_info["languageId"] = "scss"
else:
self.server_info["languageId"] = "css"

self.sender.send_notification("textDocument/didOpen", {
"textDocument": {
"uri": self.parse_document_uri(fa.filepath, fa.external_file_link),
Expand Down Expand Up @@ -500,6 +511,7 @@ def handle_workspace_configuration_request(self, name, request_id, params):
sessionSettings = settings.get(section, {})

if self.server_info["name"] == "vscode-eslint-language-server":
sessionSettings = copy.copy(settings)
Copy link
Owner

@manateelazycat manateelazycat Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why need copy here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if somewhere else will modify workspace config, resulting in changing the server info secretly. It is just defensive — we can remove it if not needed.

sessionSettings["workspaceFolder"] = {
"name": self.project_name,
"uri": path_to_uri(self.project_path),
Expand Down
Loading