Commit Graph

31 Commits

Author SHA1 Message Date
Alex Hoppen
c36a854e7a Wrap request and notification ID for the purpose of logging scopes
OSLog only allows the creation of 4000 logger objects, which means that logging will crash on the 4000th request to sourcekit-lsp (which would create the 4000th os_log object because it is the 4000th distinct category in which we are logging).

To circumvent this problem, only use the last two digits of the request and notification ID for the logging scope and wrap around afterwards. This should still allow us to tell apart log messages from concurrently handled requests/notifications while only using 200 os_log objects, which means we stay well clear of the 4000 limit.

rdar://119221355
2023-12-14 08:22:36 -08:00
Saleem Abdulrasool
8f53d08b50 build: correct dependencies
The changes in #945 changed the dependencies but did not correct them in
the CMakeLists.txt resulting in a broken build.  Resynchronise the
dependencies across Package.swift and CMake.
2023-11-01 11:12:08 -07:00
Alex Hoppen
ac3eb32e65 Format sources with swift-format 2023-10-31 19:30:31 -07:00
Alex Hoppen
1a23153fd5 When sourcekitd crashes, log the file contents with which it crashed and the request
This should make it a lot easier to reproduce sourcekitd crashes.
2023-10-31 08:30:54 -07:00
Alex Hoppen
33fa4c5487 Merge pull request #951 from ahoppen/ahoppen/signpost
Emit signposts for request handling
2023-10-31 08:27:24 -07:00
Alex Hoppen
e45efa7a44 Merge pull request #957 from ahoppen/ahoppen/always-prefix-for-orlog
Always require a prefix for `orLog` calls
2023-10-31 08:25:28 -07:00
Alex Hoppen
c37b4b8a8c Always require a prefix for orLog calls
Otherwise it’s very easy to end up with log messages like `requestCancelled` for which it’s not clear where they are coming from.
2023-10-30 16:55:50 -07:00
Alex Hoppen
47e7a13ce6 Emit signposts for request handling
This allows you to trace sourcekit-lsp in Instruments to get a feeling for how long requests take to be handled.
2023-10-30 13:53:59 -07:00
Alex Hoppen
c151216767 Default to a debug log level in NonDarwin Logger if sourcekit-lsp is built in debug mode
That way you get full log output when running tests on Linux by default, which makes debugging easier.
2023-10-30 12:57:00 -07:00
Alex Hoppen
8074a430f6 Fix issue that SOURCEKITLSP_LOG_LEVEL was not applied
The initializer of `NonDarwinLogLevel` always returned `nil`, even if a valid value was passed. Thus, the log level was always `default`, independent of the value passed to `SOURCEKITLSP_LOG_LEVEL`.
2023-10-30 12:54:43 -07:00
Alex Hoppen
cb21f9a864 Output a --- marker to mark the end of a log message in NonDarwinLogger
Figuring out where one log message ends and the next one starts is a little tricky. A `---` marker helped me a lot to find the boundary between two log messages.
2023-10-24 17:56:34 -07:00
Alex Hoppen
86751b8b74 Use NonDarwinLogger when running tests instead of os_log
'swift test' doesn't print os_log output to the command line. Use the  `NonDarwinLogger` that prints to stderr so we can view the log output in CI test runs.
2023-10-16 13:37:43 -07:00
Alex Hoppen
f960d7ed9b Change logging to use OSLog
OSLog is the suggesting logging solution on Apple platforms and we should be using it there, taking advantage of the different log levels and privacy masking.

Switch sourcekit-lsp to use OSLog on Apple platforms and implement a logger that is API-compatible with OSLog for all uses in sourcekit-lsp and which can be used on non-Darwin platforms.

The goal of this commit is to introduce the new logging API. There are still improvements about what we log and we can display more privacy-insensitive information after masking. Those changes will be in follow-up commits.
2023-10-13 13:46:32 -07:00
Alex Hoppen
d0fc00ce98 Format using swift-format
Add `.swift-format` to the repo and format the repo with `swift-format`.

This commit does not add any automation to enforce formatting of sourcekit-lsp in CI. The goal of this commit is to get the majority of source changes out of the way so that the diff of actually enforcing formatting will have fewer changes or conflicts.
2023-10-10 13:44:47 -07:00
Alex Hoppen
c4e50974d1 Make all the methods in ToolchainLanguageServer async
This is a preparation step for making `SwiftLanguageServer` and `ClangLanguageServerShim` actors.
2023-10-02 09:43:51 -07:00
Alex Hoppen
b22af35eb1 Revert asyncificaiton changes
The asyncification changes caused some non-deterministic test failures. I believe that some of these are due to race conditions that are the result of the partial transition to actors.

Instead of merging the asyncification piece by piece, I will collect the changes asyncification changes in a branch and then qualify that branch througougly (running CI multiple times) before merging it into `main`.
2023-09-30 10:09:59 -07:00
Alex Hoppen
0b345738a6 Make all the methods in ToolchainLanguageServer async
This is a preparation step for making `SwiftLanguageServer` and `ClangLanguageServerShim` actors.
2023-09-28 22:37:41 -07:00
Ben Barham
762532539e Revert "Make all the methods in ToolchainLanguageServer async"
This reverts commit a8b84256b3.
2023-09-28 15:51:21 -07:00
Alex Hoppen
a8b84256b3 Make all the methods in ToolchainLanguageServer async
This is a preparation step for making `SwiftLanguageServer` and `ClangLanguageServerShim` actors.
2023-09-27 16:20:52 -07:00
Saleem Abdulrasool
fca0cd3913 build: build SourceKit-LSP with static linking
This adjusts the sourcekit-lsp build to use static linking for the
internal libraries.  It is not currently possible to build
SourceKitLSP.dll as that requires re-exporting the interfaces from the
consumed modules.  However, this allows us to reduce the overall size of
the distribution of SourceKit-LSP by ~1 MiB and reduces the
distributed file set.  The values here assume partial static linking of
swift-package-manager, which helps reduce the total size.

Before:

   228,352 BuildServerProtocol.dll
 1,773,056 LanguageServerProtocol.dll
   114,688 LanguageServerProtocolJSONRPC.dll
    49,152 LSPLogging.dll
   262,656 SKCore.dll
    54,784 SKSupport.dll
    80,896 SKSwiftPMWorkspace.dll
   150,528 SourceKitD.dll
   645,632 SourceKitLSP.dll

    70,144 sourcekit-lsp.exe

 3,429,888 bytes

After:

 2,416,640 sourcekit-lsp.exe

 2,416,640 bytes
2022-03-02 08:43:06 -08:00
Saleem Abdulrasool
d888252350 build: force link against dependencies
This will add an additional link request for dispatch and Foundation
libraries.  These are really required on non-Darwin targets, and should
be satisfied either by the library search path or by explicitly
indicating where the dependencies can be found.
2022-02-27 12:10:30 -08:00
Kyle
4cefb7f08b Fix deprecated os_log warning 2021-12-07 00:18:12 +08:00
Kyle
6d1b09ad5b Remove available check below macOS 10.15.4
Since the Package.swift declare the minimal target for macOS is 10.15.4,
we can remove the uncessary available check code
2021-12-05 17:07:34 +08:00
Fredrik Wieczerkowski
17f656865d Implement lexical and semantic highlighting for Swift
This is an implementation of LSP's semantic tokens for Swift. Both
lexical and semantic tokens are provided by using the syntaxmap and the
semantic annotations provided as part of SourceKit's open responses and
document update notifications.

While lexical tokens are parsed and stored in the DocumentManager
synchronously, semantic tokens are provided asynchronously. If an edit
occurs, tokens are automatically shifted by the DocumentManager. This is
especially relevant for lexical tokens, which are updated in deltas.

In addition, unit tests are added that assert that both lexical and
semantic tokens are provided and shifted correctly upon edits.
2021-08-24 16:49:52 +02:00
Ben Langmuir
b329f5fea4 [logging] Don't pass arbitrary string to NSLog
NSLog expects a format string, so don't pass it arbitrary log strings,
which may contain format specifiers.
2021-05-24 09:34:22 -07:00
Saleem Abdulrasool
67aaa09d70 build: allow building with dispatch and Foundation from the toolchain
This allows building without dispatch and Foundation build roots, which
allows for a multi-phase build.  This is intended to support the Windows
staged build where dispatch and Foundation are part of the SDK and
SourceKit-LSP is part of the devtools.
2020-10-07 19:08:02 -07:00
David Goldman
482a98893f Log to stderr instead of sending window/logMessage
- clangd itself already logs to stderr so sourcekit-lsp
  should do the same for consistency (unless we want to
  capture clangd's stderr and forward it in the LSP)

- Editors such as VS Code will show stderr output in the same
  output channel where it shows logMessage + traces

Change-Id: Iaf00cffa2e64d8490e21b49a3a9d34a17f54aa9f
2020-10-06 19:18:20 -04:00
Ben Langmuir
e7f765747b Fix ExpressibleByArgument conformance on LogLevel
The initializer is failable, not throwing, and there is a default
conformance provided via the integer literal that was not correct.
2020-09-25 14:15:59 -07:00
Ben Langmuir
fa8acc142f [fixit] Handle multi-edit fixits
We were treating arrays of fixits as if they were independent actions,
but in reality we have at most one quick-fix per diagnostic, which is
composed of multiple edits. This fixes cases like renaming a deprecated
method where there are multiple edits that need to be combined.
2020-02-07 11:40:55 -08:00
Saleem Abdulrasool
54d5324613 build: add CMake build system 2019-12-04 16:47:34 -08:00
Ben Langmuir
775e198f77 Rename LSPSupport -> LSPLogging to reflect reduced scope
Ideally we can someday migrate this to something more standard such as
swift-log, and make it explicit how to control logging for the JSONRPC
module.
2019-11-19 11:08:31 -08:00