bmontegani
(Bruce Montegani)
1
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
blangmuir
(Ben Langmuir)
2
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.
bmontegani
(Bruce Montegani)
3
Here is what is in the container:
vscode@bb75cec799d7:/workspaces/myProject$ ls .build/x86_64-unknown-linux-gnu/
build.db debug
vscode@bb75cec799d7:/workspaces/myProject$ ls .build/x86_64-unknown-linux-gnu/debug
App.build NIOConcurrencyHelpers.swiftmodule
App.swiftdoc NIOConcurrencyHelpers.swiftsourceinfo
App.swiftmodule NIOExtras.build
App.swiftsourceinfo NIOExtras.swiftdoc
AsyncHTTPClient.build NIOExtras.swiftmodule
AsyncHTTPClient.swiftdoc NIOExtras.swiftsourceinfo
AsyncHTTPClient.swiftmodule NIOExtrasPerformanceTester.product
AsyncHTTPClient.swiftsourceinfo NIOFoundationCompat.build
AsyncKit.build NIOFoundationCompat.swiftdoc
AsyncKit.swiftdoc NIOFoundationCompat.swiftmodule
AsyncKit.swiftmodule NIOFoundationCompat.swiftsourceinfo
AsyncKit.swiftsourceinfo NIOHPACK.build
Backtrace.build NIOHPACK.swiftdoc
Backtrace.swiftdoc NIOHPACK.swiftmodule
Backtrace.swiftmodule NIOHPACK.swiftsourceinfo
Backtrace.swiftsourceinfo NIOHTTP1.build
CBacktrace.build NIOHTTP1.swiftdoc
CBase32.build NIOHTTP1.swiftmodule
CBcrypt.build NIOHTTP1.swiftsourceinfo
CCryptoBoringSSL.build NIOHTTP2.build
CCryptoBoringSSLShims.build NIOHTTP2.swiftdoc
CMultipartParser.build NIOHTTP2.swiftmodule
CNIOAtomics.build NIOHTTP2.swiftsourceinfo
CNIOBoringSSL.build NIOHTTP2PerformanceTester.product
CNIOBoringSSLShims.build NIOHTTP2Server.product
CNIODarwin.build NIOHTTPCompression.build
CNIOExtrasZlib.build NIOHTTPCompression.swiftdoc
CNIOHTTPParser.build NIOHTTPCompression.swiftmodule
CNIOLinux.build NIOHTTPCompression.swiftsourceinfo
CNIOSHA1.build NIOSSL.build
CNIOWindows.build NIOSSL.swiftdoc
COperatingSystem.build NIOSSL.swiftmodule
COperatingSystem.swiftdoc NIOSSL.swiftsourceinfo
COperatingSystem.swiftmodule NIOSSLHTTP1Client.product
COperatingSystem.swiftsourceinfo NIOTLS.build
CURLParser.build NIOTLS.swiftdoc
ConsoleKit.build NIOTLS.swiftmodule
ConsoleKit.swiftdoc NIOTLS.swiftsourceinfo
ConsoleKit.swiftmodule NIOTLSServer.product
ConsoleKit.swiftsourceinfo NIOTSHTTPClient.product
CoreMetrics.build NIOTSHTTPServer.product
CoreMetrics.swiftdoc NIOTransportServices.build
CoreMetrics.swiftmodule NIOTransportServices.swiftdoc
CoreMetrics.swiftsourceinfo NIOTransportServices.swiftmodule
Crypto.build NIOTransportServices.swiftsourceinfo
Crypto.swiftdoc NIOWebSocket.build
Crypto.swiftmodule NIOWebSocket.swiftdoc
Crypto.swiftsourceinfo NIOWebSocket.swiftmodule
HTTPServerWithQuiescingDemo.product NIOWebSocket.swiftsourceinfo
Leaf.build NIOWritePCAPDemo.product
Leaf.swiftdoc NIOWritePartialPCAPDemo.product
Leaf.swiftmodule RoutingKit.build
Leaf.swiftsourceinfo RoutingKit.swiftdoc
LeafKit.build RoutingKit.swiftmodule
LeafKit.swiftdoc RoutingKit.swiftsourceinfo
LeafKit.swiftmodule Run
LeafKit.swiftsourceinfo Run.build
Logging.build Run.product
Logging.swiftdoc Run.swiftdoc
Logging.swiftmodule Run.swiftmodule
Logging.swiftsourceinfo Run.swiftsourceinfo
Metrics.build Vapor.build
Metrics.swiftdoc Vapor.swiftdoc
Metrics.swiftmodule Vapor.swiftmodule
Metrics.swiftsourceinfo Vapor.swiftsourceinfo
ModuleCache WebSocketKit.build
NIO.build WebSocketKit.swiftdoc
NIO.swiftdoc WebSocketKit.swiftmodule
NIO.swiftmodule WebSocketKit.swiftsourceinfo
NIO.swiftsourceinfo description.json
NIOConcurrencyHelpers.build index
NIOConcurrencyHelpers.swiftdoc myProjectPackageTests.product
bmontegani
(Bruce Montegani)
4
Here are my settings for the extensions in the container:
{
"lldb.library": "/usr/lib/liblldb.so",
"sourcekit-lsp.serverPath": "/usr/bin/sourcekit-lsp",
"sourcekit-lsp.trace.server": "messages"
}
the swift executable is also in /usr/bin
blangmuir
(Ben Langmuir)
5
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)
bmontegani
(Bruce Montegani)
6
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 am trying to trace using verbose mode
bmontegani
(Bruce Montegani)
7
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.
bmontegani
(Bruce Montegani)
8
Ok.. question?
The workspaces directory has the following permissions:
drwxr-xr-x 3 root root 4096 Dec 22 17:00 workspaces
The myProject directory has the following permissions:
drwxr-xr-x 19 vscode vscode 608 Dec 22 17:27 myProject
Is it possible that this a permissions issue?
bmontegani
(Bruce Montegani)
9
ok... I confirmed that it is a permission issue.
Here is the docker file:
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?
Thanks for all your help
blangmuir
(Ben Langmuir)
10
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?
bmontegani
(Bruce Montegani)
11
This is weird,. So I uncommented out the #USER $USERNAME in the docker file and rebuilt the container and ran it.
Now the modules are being recognized.
I don't get it. Why did it not work before? I am confused. You are right, permissions are the same. I then cleaned the project and rebuilt it.
Still works. This is weird.