Skip to content

Commit

Permalink
feat: merge 'lsp-docker-get-server-container-name' and 'lsp-docker-ge…
Browse files Browse the repository at this point in the history
…t-server-image-name' functions, improve error message
  • Loading branch information
sfavazza committed Dec 9, 2023
1 parent 73a1b8b commit 1a51778
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions lsp-docker.el
Original file line number Diff line number Diff line change
Expand Up @@ -352,17 +352,9 @@ be bigger than default servers in order to override them)")
(intern lsp-server-subtype)
lsp-server-subtype))))

(defun lsp-docker-get-server-container-name (server-config)
"Get the server container name from the SERVER-CONFIG hash-table"
(let* ((lsp-server-subtype (gethash 'subtype server-config)))
(if (equal lsp-server-subtype "container")
(gethash 'name server-config))))

(defun lsp-docker-get-server-image-name (server-config)
"Get the server image name from the SERVER-CONFIG hash-table"
(let* ((lsp-server-subtype (gethash 'subtype server-config)))
(if (equal lsp-server-subtype "image")
(gethash 'name server-config))))
(defun lsp-docker-get-server-container/image-name (server-config)
"Get the server container/image name from the SERVER-CONFIG hash-table"
(gethash lsp-docker--srv-cfg-name-key server-config))

(defun lsp-docker-get-server-id (server-config)
"Get the server id from the SERVER-CONFIG hash-table"
Expand All @@ -375,9 +367,9 @@ be bigger than default servers in order to override them)")
dockerized client to be built upon"
(if-let* ((base-client (gethash base-server-id lsp-clients)))
base-client
(user-error "Cannot find a specified base lsp client!
(user-error "Cannot find the specified base lsp client (%s)!
Make sure the '%s' sub-key is set to one of the lsp registered clients:\n\n%s"
lsp-docker--srv-cfg-type-key (ht-keys lsp-clients))))
base-server-id lsp-docker--srv-cfg-server-key (ht-keys lsp-clients))))

(defun lsp-docker-get-path-mappings (config project-directory)
"Get the server path mappings from the top project hash-table CONFIG"
Expand Down Expand Up @@ -673,8 +665,7 @@ configuration file resides into. The PATH-MAPPINGS provides a
hash-table to translate the paths between the host and the
dockerized server."
(let* ((server-type-subtype (lsp-docker-get-server-type-subtype server-config))
(config-specified-server-container-name (lsp-docker-get-server-container-name server-config))
(server-image-name (lsp-docker-get-server-image-name server-config))
(server-container/image-name (lsp-docker-get-server-container/image-name server-config))
(regular-server-id (lsp-docker-get-server-id server-config))
(server-id (lsp-docker-generate-docker-server-id server-config (lsp-workspace-root)))
(server-launch-command (lsp-docker-get-launch-command server-config))
Expand All @@ -683,7 +674,7 @@ dockerized server."
(lsp-workspace-root)
base-client))
(server-container-name (lsp-docker--finalize-docker-server-container-name
config-specified-server-container-name server-config project-root)))
server-container/image-name server-config project-root)))

(if (and (lsp-docker-check-server-type-subtype lsp-docker-supported-server-types-subtypes
server-type-subtype)
Expand All @@ -692,19 +683,19 @@ dockerized server."
(container-subtype (cdr server-type-subtype)))
(pcase container-type
('docker (pcase container-subtype
('image (if (lsp-docker--check-image-exists server-image-name)
('image (if (lsp-docker--check-image-exists server-container/image-name)
(lsp-docker-register-client-with-activation-fn
:server-id regular-server-id
:docker-server-id server-id
:path-mappings path-mappings
:docker-image-id server-image-name
:docker-image-id server-container/image-name
:docker-container-name server-container-name
:activation-fn activation-fn
:priority lsp-docker-default-priority
:server-command server-launch-command
:launch-server-cmd-fn #'lsp-docker-launch-new-container)
(lsp-docker--build-image-and-register-server-async
:image-name server-image-name
:image-name server-container/image-name
:dockerfile-path (lsp-docker--find-project-dockerfile-from-lsp)
:server-id regular-server-id
:docker-server-id server-id
Expand Down

0 comments on commit 1a51778

Please sign in to comment.