Skip to content

Commit

Permalink
Merge pull request #48 from sublimelsp/issue/43
Browse files Browse the repository at this point in the history
  • Loading branch information
TerminalFi authored Apr 29, 2023
2 parents 2b78ef1 + 7ffa142 commit be5c1e7
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 6 deletions.
76 changes: 76 additions & 0 deletions LSP-gopls.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,27 @@
],
"selector": "source.go | source.gomod",
"settings": {
// Controls if LSP-gopls will automatically install and upgrade gopls.
// If this option is set to `False` the user will need to update the
// `command` to point to a valid gopls binary.
"manageGoplsBinary": true,

// Controls if the Terminus panel/tab will auto close on tests completing.
"closeTestResultsWhenFinished": false,

// Controls if the test results output to a panel instead of a tab.
"runTestsInPanel": true,

// buildFlags is the set of flags passed on to the build system when invoked.
// It is applied to queries like `go list`, which is used when discovering files.
// The most common use is to set `-tags`.
//
"gopls.buildFlags": [],

// env adds environment variables to external commands run by `gopls`, most notably `go list`.
//
"gopls.env": {},

// directoryFilters can be used to exclude unwanted directories from the
// workspace. By default, all directories are included. Filters are an
// operator, `+` to include and `-` to exclude, followed by a path prefix
Expand All @@ -33,46 +44,62 @@
// Include only project_a: `-` (exclude everything), `+project_a`
//
// Include only project_a, but not node_modules inside it: `-`, `+project_a`, `-project_a/node_modules`
//
"gopls.directoryFilters": [
"-**/node_modules"
],

// templateExtensions gives the extensions of file names that are treateed
// as template files. (The extension
// is the part of the file name after the final dot.)
//
"gopls.templateExtensions": [],

// (experimental) memoryMode controls the tradeoff `gopls` makes between memory usage and
// correctness.
//
// Values other than `Normal` are untested and may break in surprising ways.
//
"gopls.memoryMode": "Normal",

// (experimental) expandWorkspaceToModule instructs `gopls` to adjust the scope of the
// workspace to find the best available module root. `gopls` first looks for
// a go.mod file in any parent directory of the workspace folder, expanding
// the scope to that directory if it exists. If no viable parent directory is
// found, gopls will check if there is exactly one child directory containing
// a go.mod file, narrowing the scope to that directory if it exists.
//
"gopls.expandWorkspaceToModule": true,

// (experimental) experimentalWorkspaceModule opts a user into the experimental support
// for multi-module workspaces.
//
// Deprecated: this feature is deprecated and will be removed in a future
// version of gopls (https://go.dev/issue/55331).
//
"gopls.experimentalWorkspaceModule": false,

// (experimental) experimentalPackageCacheKey controls whether to use a coarser cache key
// for package type information to increase cache hits. This setting removes
// the user's environment, build flags, and working directory from the cache
// key, which should be a safe change as all relevant inputs into the type
// checking pass are already hashed into the key. This is temporarily guarded
// by an experiment because caching behavior is subtle and difficult to
// comprehensively test.
//
"gopls.experimentalPackageCacheKey": true,

// (experimental) allowModfileModifications disables -mod=readonly, allowing imports from
// out-of-scope modules. This option will eventually be removed.
//
"gopls.allowModfileModifications": false,

// (experimental) allowImplicitNetworkAccess disables GOPROXY=off, allowing implicit module
// downloads rather than requiring user action. This option will eventually
// be removed.
//
"gopls.allowImplicitNetworkAccess": false,

// standaloneTags specifies a set of build constraints that identify
// individual Go source files that make up the entire main package of an
// executable.
Expand All @@ -91,12 +118,16 @@
// main file.
//
// This setting is only supported when gopls is built with Go 1.16 or later.
//
"gopls.standaloneTags": [
"ignore"
],

// hoverKind controls the information that appears in the hover text.
// SingleLine and Structured are intended for use only by authors of editor plugins.
//
"gopls.hoverKind": "FullDocumentation",

// linkTarget controls where documentation links go.
// It might be one of:
//
Expand All @@ -107,29 +138,45 @@
//
// Modules matching the GOPRIVATE environment variable will not have
// documentation links in hover.
//
"gopls.linkTarget": "pkg.go.dev",

// linksInHover toggles the presence of links to documentation in hover.
//
"gopls.linksInHover": true,

// placeholders enables placeholders for function parameters or struct
// fields in completion responses.
//
"gopls.usePlaceholders": false,

// (debug) completionBudget is the soft latency goal for completion requests. Most
// requests finish in a couple milliseconds, but in some cases deep
// completions can take much longer. As we use up our budget we
// dynamically reduce the search scope to ensure we return timely
// results. Zero means unlimited.
//
"gopls.completionBudget": "100ms",

// (advanced) matcher sets the algorithm that is used when calculating completion
// candidates.
//
"gopls.matcher": "Fuzzy",

// (experimental) experimentalPostfixCompletions enables artificial method snippets
// such as "someSlice.sort!".
//
"gopls.experimentalPostfixCompletions": true,

// importShortcut specifies whether import statements should link to
// documentation or go to definitions.
//
"gopls.importShortcut": "Both",

// (advanced) symbolMatcher sets the algorithm that is used when finding workspace symbols.
//
"gopls.symbolMatcher": "FastFuzzy",

// (advanced) symbolStyle controls how symbols are qualified in symbol responses.
//
// Example Usage:
Expand All @@ -141,7 +188,9 @@
// ...
// }
// ```
//
"gopls.symbolStyle": "Dynamic",

// analyses specify analyses that the user would like to enable or disable.
// A map of the names of analysis passes that should be enabled/disabled.
// A full list of analyzers that gopls uses can be found in
Expand All @@ -157,28 +206,38 @@
// }
// ...
// ```
//
"gopls.analyses": {},

// (experimental) staticcheck enables additional analyses from staticcheck.io.
// These analyses are documented on
// [Staticcheck's website](https://staticcheck.io/docs/checks/).
//
"gopls.staticcheck": false,

// (experimental) annotations specifies the various kinds of optimization diagnostics
// that should be reported by the gc_details command.
//
"gopls.annotations": {
"bounds": true,
"escape": true,
"inline": true,
"nil": true
},

// (experimental) vulncheck enables vulnerability scanning.
//
"gopls.vulncheck": "Off",

// (advanced) diagnosticsDelay controls the amount of time that gopls waits
// after the most recent file modification before computing deep diagnostics.
// Simple diagnostics (parsing and type-checking) are always run immediately
// on recently modified packages.
//
// This option must be set to a valid duration string, for example `"250ms"`.
//
"gopls.diagnosticsDelay": "250ms",

// (experimental) experimentalWatchedFileDelay controls the amount of time that gopls waits
// for additional workspace/didChangeWatchedFiles notifications to arrive,
// before processing all such notifications in a single batch. This is
Expand All @@ -189,11 +248,15 @@
//
// Deprecated: this setting is deprecated and will be removed in a future
// version of gopls (https://go.dev/issue/55332)
//
"gopls.experimentalWatchedFileDelay": "0s",

// (experimental) hints specify inlay hints that users want to see. A full list of hints
// that gopls uses can be found in
// [inlayHints.md](https://github.com/golang/tools/blob/master/gopls/doc/inlayHints.md).
//
"gopls.hints": {},

// codelenses overrides the enabled/disabled state of code lenses. See the
// "Code Lenses" section of the
// [Settings page](https://github.com/golang/tools/blob/master/gopls/doc/settings.md#code-lenses)
Expand All @@ -211,6 +274,7 @@
// ...
// }
// ```
//
"gopls.codelenses": {
"gc_details": false,
"generate": true,
Expand All @@ -219,21 +283,33 @@
"upgrade_dependency": true,
"vendor": true
},

// (experimental) semanticTokens controls whether the LSP server will send
// semantic tokens to the client.
//
"gopls.semanticTokens": false,

// (experimental) noSemanticString turns off the sending of the semantic token 'string'
//
"gopls.noSemanticString": false,

// (experimental) noSemanticNumber turns off the sending of the semantic token 'number'
//
"gopls.noSemanticNumber": false,

// local is the equivalent of the `goimports -local` flag, which puts
// imports beginning with this string after third-party packages. It should
// be the prefix of the import path whose imports should be grouped
// separately.
//
"gopls.local": "",

// gofumpt indicates if we should run gofumpt formatting.
//
"gopls.gofumpt": false,

// (debug) verboseOutput enables additional debug logging.
//
"gopls.verboseOutput": false,
}
}
1 change: 1 addition & 0 deletions plugin/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

PACKAGE_NAME = __package__.partition('.')[0]
SESSION_NAME = 'gopls'
SETTINGS = 'LSP-gopls.sublime-settings'

TAG = '0.11.0'
GOPLS_BASE_URL = 'golang.org/x/tools/gopls@v{tag}'
Expand Down
4 changes: 4 additions & 0 deletions plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .constants import SESSION_NAME

from .utils import get_setting
from .utils import get_settings
from .utils import to_int
from .utils import is_binary_available
from .utils import run_go_command
Expand Down Expand Up @@ -133,6 +134,9 @@ def _set_env_vars(cls) -> dict:

@classmethod
def needs_update_or_installation(cls) -> bool:
is_managed = get_settings().get('settings', {}).get('manageGoplsBinary', True)
if not is_managed:
return False
return not cls._is_gopls_installed() or (
cls.server_version() != cls.current_server_version()
)
Expand Down
6 changes: 6 additions & 0 deletions plugin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from LSP.plugin.core.typing import Any
from LSP.plugin.core.typing import Tuple

from .constants import SETTINGS


def get_setting(
session: Session,
Expand All @@ -24,6 +26,10 @@ def get_setting(
return value


def get_settings():
return sublime.load_settings(SETTINGS)


def run_go_command(
env_vars: dict,
sub_command: str = "install",
Expand Down
13 changes: 9 additions & 4 deletions scripts/update-schema-settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,19 @@

# Custom LSP-gopls settings not provided by gopls directly
CUSTOM_PROPERTIES = {
'manageGoplsBinary': {
'default': True,
'markdownDescription': 'Controls if LSP-gopls will automatically install and upgrade gopls.\nIf this option is set to `False` the user will need to update the\n`command` to point to a valid gopls binary.',
'type': 'boolean'
},
'closeTestResultsWhenFinished': {
'default': False,
'markdownDescription': 'Controls if the Terminus panel/tab will auto close on tests completing.\n',
'markdownDescription': 'Controls if the Terminus panel/tab will auto close on tests completing.',
'type': 'boolean',
},
'runTestsInPanel': {
'default': True,
'markdownDescription': 'Controls if the test results output to a panel instead of a tab.\n',
'markdownDescription': 'Controls if the test results output to a panel instead of a tab.',
'type': 'boolean',
},
}
Expand Down Expand Up @@ -189,14 +194,14 @@ def generate_lsp_settings(self) -> str:
[
f'{PREFIX_LSP_GOPLS_SETTINGS}// {line}'.rstrip()
for line in properties[prop]['markdownDescription'].split('\n')
][:-1]
]
)
defaults = json.dumps(properties[prop]["default"], indent=2)
defaults = '\n'.join(
[f'{PREFIX_LSP_GOPLS_SETTINGS}{line}' for line in defaults.split('\n')]
)
defaults = f'{PREFIX_LSP_GOPLS_SETTINGS}"{prop}": {defaults.lstrip()},'
compiled_settings += lines + '\n' + defaults + '\n'
compiled_settings += lines + '\n' + defaults + '\n\n'
self.gopls_settings = (
BEGIN_LSP_GOPLS_SETTINGS
+ compiled_settings.rstrip()
Expand Down
9 changes: 7 additions & 2 deletions sublime-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@
"additionalProperties": false,
"type": "object",
"properties": {
"manageGoplsBinary": {
"default": true,
"markdownDescription": "Controls if LSP-gopls will automatically install and upgrade gopls.\nIf this option is set to `False` the user will need to update the\n`command` to point to a valid gopls binary.",
"type": "boolean"
},
"closeTestResultsWhenFinished": {
"default": false,
"markdownDescription": "Controls if the Terminus panel/tab will auto close on tests completing.\n",
"markdownDescription": "Controls if the Terminus panel/tab will auto close on tests completing.",
"type": "boolean"
},
"runTestsInPanel": {
"default": true,
"markdownDescription": "Controls if the test results output to a panel instead of a tab.\n",
"markdownDescription": "Controls if the test results output to a panel instead of a tab.",
"type": "boolean"
},
"gopls.buildFlags": {
Expand Down

0 comments on commit be5c1e7

Please sign in to comment.