reference Commands

opengrep lsp

See also
opengrep scan, HOME
opengrep lsp [FLAGS]

Starts a Language Server Protocol server that scans the files open in an editor and reports the findings as diagnostics. The command is meant to be started by an editor. It reads JSON-RPC messages with Content-Length framing on standard input and writes its responses to standard output; there is no other transport.

Settings

The rules and the scan settings come from the client, in the scan object of the initializationOptions of the initialize request:

{
  "scan": {
    "configuration": ["/path/to/rules.yaml"],
    "exclude": ["tests/"],
    "onlyGitDirty": false,
    "taintIntrafile": true
  }
}
SettingEquivalent flagDefaultMeaning
configuration--confignoneThe rules, as a list of files, directories or other configuration sources.
include--includenoneScan only the files that match one of these patterns.
exclude--excludenoneSkip the files that match one of these patterns.
onlyGitDirtytrueIn a git repository, report only the findings on lines that differ from the last commit.
taintIntrafile--taint-intrafilefalseFollow taint through calls to functions in the same file.
maxTargetBytes--max-target-bytes1000000Skip files larger than this many bytes.
maxMatchPerFile--max-match-per-file10000The number of matches in a file above which its findings are dropped.
jobs--jobsthe number of coresThe number of parallel workers.
maxMemory--max-memory0, no limitThe memory limit of a scan, in MiB.
timeout--timeout30The time limit of a rule on a file, in seconds.
timeoutThreshold--timeout-threshold3The number of timeouts after which a file is skipped.
dynamicTimeout--dynamic-timeoutfalseScale the timeout with the size of the file.
dynamicTimeoutMaxMultiplier--dynamic-timeout-max-multiplier20The largest factor by which the timeout is scaled.
dynamicTimeoutUnitKb--dynamic-timeout-unit-kb30The file size, in KB, of one step of the scaling.
allowRuleTimeoutControl--allow-rule-timeout-controlfalseLet rules set their own time limits.

The server scans each document that the editor opens.

Exit status

0 when the client ends the session, 2 on a fatal error, and 141 when the program that reads the output closed the pipe.

Flags

FlagSummary
--debugLog the messages of --verbose and the diagnostics of the engine.
--developListed in Internal and debugging interfaces.
--profileListed in Internal and debugging interfaces.
--quietPrint only the findings, and nothing on standard error.
--verboseLog the progress of the run, at the info level.

Examples

Starting the server

An editor starts the command and then communicates with it over standard input and output. When started from a shell, the server prints nothing: it waits for the initialize request of a client and answers on standard output.

Command
$ opengrep lsp