I am using VSCode Remote Containers to run a native linux environment.
I am using Swift 5.3.2 Ubuntu 18.04 running in a docker container.
I can build the project. However, None of the imports work. For instance, I use import Vapor and there is a red squiggle under Vapor that says " no such module Vapor"
I have the SourceKit-LSP running in the container. I have tried to rebuild but it still gives me the same messages.
BTW, This works fine under macOS Catalina in VSCode. (no container)
Has anyone else tried to use SourceKit-LSP in VSCode Remote Containers who might know the cause of this?
Upon further research I have the following message from the SourceKit language server:
sourcekit-lsp[220:dcff4700] could not open compilation database for /workspaces/myProject/Sources/App/routes.swift
SourceKit-LSP uses your build directory (e.g. .build/x86_64-unknown-linux/debug) to find dependent modules. If you're running in a container, that is probably missing. If you can login to the container as it is running you could build manually there as a workaround. Or if you can customize the container setup maybe you can get it to build the project as part of that step.
Okay, interesting. You mentioned seeing the warning about the compilation database - do you see any of the following logs? They would be right around the initialize request
} catch Error.noManifest(let path) {
log("could not find manifest, or not a SwiftPM package: \(path)", level: .warning)
return nil
} catch {
log("failed to create \(SwiftPMWorkspace.self): \(error)", level: .error)
After further research it looks like the could not open compilation database
message doesn't really matter because I get the same message on MacOS without docker and it works fine.
I have tried under verbose mode and the only log message I get is:
2020-12-22 17:49:51.628 sourcekit-lsp[6278:3effd700] could not open compilation database for /workspaces/myProject/Sources/App/Modules/Frontend/FrontendController.swift
[Trace - 5:49:51 PM] Received notification 'window/logMessage'.
Params: {
"type": 4,
"message": "could not open compilation database for /workspaces/myProject/Sources/App/Modules/Frontend/FrontendController.swift"
}
Actually I receive numerous message of the same type depending on which file I have open.
I checked to see if the build.db was created and even looked inside to see if there is any data. It looks like it created fine.
FROM swift:5.3.2-bionic
# Or your actual UID, GID on Linux if not the default 1000
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID
# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive
# Configure apt and install packages
RUN apt-get update \
# Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
&& groupadd --gid $USER_GID $USERNAME \
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
# [Optional] Add sudo support for non-root user
&& apt-get install -y sudo \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME \
#
# Clean up
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=
# USER $USERNAME
Notice at the bottom I have commented out the USER. When I did this it started to work.
However, I prefer not to be developing as root. Is there any other solution so that I don't have to be root?
It's unclear to me what the permissions issue is here - I would expect we need r-x permission for
"workspaces" and rwx for "myProject" (to potentially create or update the .build directory), and that is what the permissions seem to be already. Do you know what specifically it was failing on?