-
-
Notifications
You must be signed in to change notification settings - Fork 76
/
metals.txt
1394 lines (1088 loc) · 60.5 KB
/
metals.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
*metals.txt* nvim-metals
A nvim plugin for Metals utilizing Neovim's built-in LSP support.
https://scalameta.org/metals/
NVIM-METALS REFERENCE MANUAL
CONTENTS *nvim-metals*
0. Introduction ........ |metals-introduction|
1. Prerequisites........ |metals-prerequisites|
2. Getting Started...... |metals-getting-started|
3. Settings............. |metals-settings|
4. Commands............. |metals-commands|
5. LUA API.............. |metals-lua-api|
6. TVP Module........... |metals-tvp-module|
7. Custom Handlers...... |metals-custom-handlers|
8. Integrations......... |metals-integrations|
================================================================================
INTRODUCTION *metals-introduction*
nvim-metals is a Lua plugin built to provide a better experience while using
Metals, the Scala Language Server, with Neovim's built-in LSP support. This
plugin provides the necessary commands you'll need to develop with nvim and
Metals. This plugin also implements many of the custom Metals LSP
extensions that will give you a much richer experience than just using Metals
with the default nvim-lspconfig setup, as well as automatically setting all of
the correct `init_options`.
================================================================================
PREREQUISITES *metals-prerequisites*
- Ensure you're using at least Neovim v0.7.0. While `nvim-metals` will aim to
always work with the latest stable version of Neovim, there is no guarantee
of compatibility with older versions.
- WARNING: do not use this plugin for Metals in parallel with `neovim/nvim-lspconfig`.
If you've used `neovim/nvim-lspconfig` before with Metals, make sure
to remove metals setup for it as it will conflict with this plugin. NOTE:
that keeping the plugin installed for other LSP servers is totally fine,
just let `nvim-metals` handle Metals.
- https://get-coursier.io/ - Metals uses coursier to manage the installation
and updating of Metals.
- Remove `F` from `shortmess`. `set shortmess-=F` (for lua
`vim.opt_global.shortmess:remove("F")`) NOTE: Without doing this,
autocommands that deal with filetypes prohibit messages from being shown, so
some of the messages we show to help users get started may not be shown.
If you're confident you don't need help setting up, then just remove this,
and `nvim-metals` will work fine, but any log messages won't actually be
shown to you if something goes wrong with `nvim-metals`.
- Make sure you have your mappings for various LSP functionality configured.
Neovim provides functions for things like goto-definition, find references,
etc, but they need to be mapped.
- This plugin relies on https://github.com/nvim-lua/plenary.nvim which you're
more than likely already relying on for other plugins. However, make sure to
also have this installed.
- Subscribe to https://github.com/scalameta/nvim-metals/discussions/253 which
will list any breaking changes to `nvim-metals`.
- Check out the features list in
https://github.com/scalameta/nvim-metals/discussions/279. New features will
always be added there.
- If you're unfamiliar with configuring Neovim with Lua or not sure how to
call Lua from Vimscript, check out the awesome guide at
https://github.com/nanotee/nvim-lua-guide. The help docs here always assume
Lua.
================================================================================
GETTING STARTED *metals-getting-started*
Once installed, the most basic setup is to have the following: >
local nvim_metals_group = vim.api.nvim_create_augroup("nvim-metals", { clear = true })
vim.api.nvim_create_autocmd("FileType", {
pattern = { "scala", "sbt", "java" },
callback = function()
require("metals").initialize_or_attach({})
end,
group = nvim_metals_group,
})
<
This will give you the defaults that Metals provides. The empty `{}` that
is passed into |initialize_or_attach()| is necessary and is very similar to
the config object that is directly passed into the |vim.lsp.start_client()|
method. The only differences are the addition of root_patterns that can be used
to determine your root dir, and also a slightly different shaped settings. You
can see examples of how to use settings in the |metals-settings| section.
You can read more about the other config parameters in
|vim.lsp.start_client()|. This is the primary way to edit your
`init_options`, change or add any custom `handlers`, and set any configuration
settings.
WARNING: Metals offers basic Java support, but not nearly to the level of the
Java language server, so while we do have `java` in the FileType autocmd, you
may not want this if you're using something like `nvim-jdtls` for more Java
heavy projects. Since then you'd be triggering two different servers to
connect here, which you probably don't want. However, if you're primarily
using Scala and also have _some_ Java to deal with, then ensuring that `java`
is listed here is important or else Metals won't attach on Java files.
NOTE: It's highly recommended to set your `statusBarProvider` to either `"on"`
or `"off"`. By default it's set to `"show-message"` to ensure that anyone
starting out will see the messages, but this will not give you the best user
experience.
If you set it to `"off"`, you're telling Metals to use the default LSP
progress mechanism. If you do this, you'll need to ensure you have a plugin
installed that handles progress like https://github.com/j-hui/fidget.nvim, for
example. This is the recommended way.
If you set this to `"on"` it enables `metals/status`, which as a
Metals-specific LSP extension for status messages that nvim-metals makes
limited support of. However, to enable this you _must_ have the metals status
shown in your status bar somehow. This can be achieved by just accessing it
with Lua via `vim.g['metals_status']`.
You can chage the value of `statusBarProvider` like shown below: >
metals_config = require("metals").bare_config()
metals_config.init_options.statusBarProvider = "on"
<
You can also get extra status information from Metals about your BSP
connection. You can access this with `vim.g['metals_bsp_status']`. This will
either return useful messages from your build server about things like
disconnects or just the name of the build server being used.
Then instead of passing an empty `{}` to |initialize_or_attach()|, you'd pass
in `metals_config`.
Once set up, the first time you open a Scala project you'll be prompted to
install Metals. You can do this with the following command: |MetalsInstall|.
In order to install the latest snapshot of metals you can explicitly set the
snapshot version in your settings table: >
metals_config = require("metals").bare_config()
metals_config.settings = {
serverVersion = "0.10.9+131-30f6a57b-SNAPSHOT"
}
<
You can also just default to the latest snapshot by setting this to
`latest.snapshot`. NOTE: that while this will pull in the latest snapshot it
happens during the actual install, not automatically all the time. So you
still need to trigger a |:MetalsUpdate| regularly to get the newest snapshots.
If no version is set, it defaults to the latest stable release. If a new
release comes out or you change your server version, you can issue a
|MetalsUpdate| command to re-install it.
================================================================================
SETTINGS *metals-settings*
The following settings are able to be passed along with the config table to
|initialize_or_attach()|. The keys are checked to ensure that you don't pass
in a setting that is not a valid Metals setting. You can set these like the
example below shows: >
metals_config = require("metals").bare_config()
metals_config.settings = {
verboseCompilation = true,
excludedPackages = {
"akka.actor.typed.javadsl",
"com.github.swagger.akka.javadsl"
}
}
<
NOTE: there are two lists of settings below. They are all grouped under
settings and set the same way just to make it easier for the user to not have
to differentiate them, however they are handled differently internally. Some
are actually sent to the server to use and others are kept in `nvim-metals` to
set plugin related things.
All available settings:
_ones that are sent and used by the server_
* |ammoniteJvmProperties|
* |autoImportBuild|
* |bloopSbtAlreadyInstalled|
* |bloopVersion|
* |bloopJvmProperties|
* |defaultBspToBuildTool|
* |enableSemanticHighlighting|
* |excludedPackages|
* |fallbackScalaVersion|
* |gradleScript|
* |inlayHints|
* |javaFormat.eclipseConfigPath|
* |javaFormat.eclipseProfile|
* |javaHome|
* |mavenScript|
* |millScript|
* |remoteLanguageServer|
* |sbtScript|
* |scalaCliLauncher|
* |scalafixConfigPath|
* |scalafixRulesDependencies|
* |scalafmtConfigPath|
* |serverProperties|
* |superMethodLensesEnabled|
* |verboseCompilation|
_ones that are used internally by `nvim-metals`_
* |disabledMode|
* |decorationColor|
* |metalsBinaryPath|
* |serverOrg|
* |serverVersion|
* |useGlobalExecutable|
ammoniteJvmProperties *ammoniteJvmProperties*
Type: table as list ~
Default: {} ~
Optional list of JVM properties to pass along to the Ammonite server. Each
property needs to be a separate item. >
{"-Xmx1G", "-Xms100M"}
<
autoImportBuild *autoImportBuild*
Type: string ~
Default: "off" ~
Automatically import your build instead of recieving a prompt to ask you.
"initial" means that your build will only be automatically be imported upon
first opening a project.
"all" means that your build will just always be automatically imported or
reloaded upon detected changes.
bloopSbtAlreadyInstalled *bloopSbtAlreadyInstalled*
Type: boolean ~
Default: false ~
If true, Metals will not generate `metals.sbt` file under the assumption that
sbt-bloop is already manually installed in the sbt build. Build import will
fail with a 'not valid command bloopInstall' error in case Bloop is not
manually installed in the build when using this option.
bloopVersion *bloopVersion*
Type: string ~
Default: Whichever is included in your version of Metals ~
This version will be used for the Bloop build tool plugin, for any supported
build tool, while importing in Metals as well as for running the embedded
server. More than likely you'll never need to use this.
bloopJvmProperties *bloopVjmProperties*
Type: table as list ~
Default: {} ~
Optional list of JVM properties to pass along to the Bloop server. Please
follow this guide for the format
https://scalacenter.github.io/bloop/docs/server-reference#global-settings-for-the-server.
*decorationColor*
Type: string ~
Default: 'Conceal' ~
The highlight group that will be used to show decorations. For example, this
will change the way worksheet evaluations are displayed in `*.worksheet.sc`
file.
defaultBspToBuildTool *defaultBspToBuildTool*
Type: boolean ~
Default: false ~
When your build tool can also serve as your build server, default to using it
for BSP. The default is Bloop for build tools that Bloop supports.
*disabledMode*
Type: boolean ~
Default: false ~
Used in the situation where you don't want Metals to start by default when you
enter a Scala workspace. WARNING: Use this with caution though as it may be
confusing why Metals isn't starting when you're in a workspace and you forgot
you have this set. If using this, once you'd like to use Metals in a specific
workspace you'll need to manually start the server via |MetalsStartServer| or
via a mapping with |start_server()|. Then it will continue to work in that
workspace until you close it. NOTE: The choice isn't persisted, so you need to
continually do this every time you want to use it even in the same workspace.
If people _actually_ use this setting and want that, submit a feature request,
if not it's not worth the extra work.
enableSemanticHighlighting *enableSemanticHighlighting*
Type: boolean ~
Default: true ~
When this option is enabled, Metals will provide semantic tokens for clients
that support it. The feature is still experimental and does not work for
all sources.
excludedPackages *excludedPackages*
Type: table as list ~
Default: {} ~
Packages that will be excluded from completions, imports, and symbol searches.
Note: that this is in addition to some default packages that are already
excluded internally in Metals. The default excluded packages are listed below:
>
META-INF
images
toolbarButtonGraphics
jdk
sun
oracle
java.awt.desktop
org.jcp
org.omg
org.graalvm
com.oracle
com.sun
com.apple
apple
<
If there is a need to remove one of the defaults, you are able to do so by
including the package in your list and prepending `--` to it. >
["--sun"]
<
gradleScript *gradleScript*
Type: string ~
Default: '' ~
Optional absolute path to a gradle executable to use for running gradle
bloopInstall. By default, Metals uses gradlew with 5.3.1 gradle version.
Update this setting if your gradle script requires more customizations like
using environment variables.
fallbackScalaVersion *fallbackScalaVersion*
Type: string ~
Default: '' ~
The Scala compiler version that is used as the default or fallback in case a
file doesn't belong to any build target or the specified Scala version isn't
supported by Metals. This applies to standalone Scala files, worksheets,
and Ammonite scripts.
Note: Setting this to a higher version than Metals currently supports won't
work and you'll just get a warning. So don't be cheeky and think you can bump
faster than Metals can by using this.
inlayHints *inlayHints*
Type: table ~
Default: {} ~
Table of inlay hints to enable. >
{
hintsInPatternMatch = { enable = true },
implicitArguments = { enable = true },
implicitConversions = { enable = true },
inferredTypes = { enable = true },
typeParameters = { enable = true },
}
<
javaFormat.eclipseConfigPath *javaFormat.eclipseConfigPath*
Type: string ~
Default: '' ~
Optional custom path to the eclipse-formatter.xml file. Should be an absolute
path and use forward slashes `/` for file separators (even on Windows).
javaFormat.eclipseProfile *javaFormat.eclipseProfile*
Type: string ~
Default: '' ~
Optional Eclipse format profile to use.
javaHome *javaHome*
Type: string ~
Default: falls back to JAVA_HOME ~
The Java Home directory used for indexing JDK sources and locating the java
binary. This will also be forwarded to Bloop to ensure it starts using this
Java. NOTE: Due to the way nvim-metals bootstraps Metals, this setting won't
actually be used to start Metals, but rather your JAVA_HOME will be picked up
and used. You can see more details about this in
https://github.com/scalameta/nvim-metals/issues/380.
mavenScript *mavenScript*
Type: string ~
Default: '' ~
Optional absolute path to a maven executable to use for generating bloop
config. By default, Metals uses mvnw maven wrapper with 3.6.1 maven version.
Update this setting if your maven script requires more customizations
millScript *millScript*
Type: string ~
Default: '' ~
Optional absolute path to a mill executable to use for running mill
mill.contrib.Bloop/install. By default, Metals uses mill wrapper script with
0.5.0 mill version. Update this setting if your mill script requires more
customizations like using environment variables.
metalsBinaryPath *metalsBinaryPath*
Type: string ~
Default: '' ~
Another setting for you crazy Nix kids. If you'd like to pass in a specific
Metals instance that isn't a global executable, you can do so by setting this
to the absolute path of Metals.
remoteLanguageServer *remoteLanguageServer*
Type: string ~
Default: '' ~
A URL pointing to an endpoint that implements a remote language server.
See https://scalameta.org/metals/docs/integrations/remote-language-server.html
for documentation on remote language servers.
sbtScript *sbtScript*
Type: string ~
Default: '' ~
Optional absolute path to an sbt executable to use for running sbt
bloopInstall. By default, Metals uses java -jar sbt-launch.jar with an
embedded launcher while respecting .jvmopts and .sbtopts. Update this setting
if your sbt script requires more customizations like using environment
variables.
scalaCliLauncher *scalaCliLauncher*
Type: string ~
Default: '' ~
Optional absolute path to the Scala CLI launcher to use.
scalafixConfigPath *scalafixConfigPath*
Type: string ~
Default: '' ~
Optional custom path to the .scalafix.conf file. Should be an absolute path
and use forward slashes / for file separators (even on Windows).
scalafixRulesDependencies *scalafixRulesDependencies*
Type: table ~
Default: {} ~
Table of Scalafix external Scalafix dependencies for Metals to run. Example
format: `com.github.liancheng::organize-imports:0.6.0`.
scalafmtConfigPath *scalafmtConfigPath*
Type: string ~
Default: '' ~
Optional custom path to the .scalafmt.conf file. Should be an absolute path
and use forward slashes / for file separators (even on Windows).
*serverOrg*
Type: string ~
Default: 'org.scalameta' ~
Useful if you'd like to use a Metals that might be published under another
org.
*serverVersion*
Type: string ~
Default: 'latest.stable' ~
Targeted server version that you'd like to install. Note that if this is
changed you need to do a |:MetalsInstall| or |:MetalsUpdate| again to ensure
that it is installed. If you need to check what version you're currently
using, you can use the |MetalsInfo| command. NOTE: that `latest.snapshot` is
also available as a value to install whatever the latest snapshot is.
serverProperties *serverProperties*
Type: table ~
Default: {} ~
Table of properties to pass along to the Metals server. By default, the
environment variable `JAVA_OPTS` and the `.jvmopts` file are respected.
However, we care most about the proxy settings from those places, not
necessarily the memory options since Metals has different requirements for
example than sbt. So if you have proxy settings defined in `JAVA_OPTS`, then
no need to define them here again. However, if you want to set some specific
memory settings for Metals, then this is the place.
superMethodLensesEnabled *superMethodLensesEnabled*
Type: boolean ~
Default: true ~
When enabled Metals will populate code lenses for you to navigate to the
parent/super methods of members.
*useGlobalExecutable*
Type: boolean ~
Default: false ~
For all you crazy Nix kids out there, or if you want to re-use the same
executable for multiple clients, this is for you. Please NOTE that by doing
this, you are fully taking control of updating and installing Metals. Unless
there is a specific reason that you want to manage your own version and
install manually, then I'd recommend not using this setting and just letting
`nvim-metals` handle it.
*verboseCompilation*
Type: boolean ~
Default: false ~
If a build server supports it (for example Bloop or Scala CLI), setting it to
true will make the logs contain all the possible debugging information
including that about incremental compilation in Zinc.
================================================================================
COMMANDS *metals-commands*
The following commands are provided by `nvim-metals`:
* |MetalsAnalyzeStacktrace|
* |MetalsCompileCancel|
* |MetalsCompileCascade|
* |MetalsCompileClean|
* |MetalsConnectBuild|
* |MetalsCopyWorksheetOutput|
* |MetalsDisconnectBuild|
* |MetalsFindInDependencyJars|
* |MetalsGenerateBspConfig|
* |MetalsGotoSuperMethod|
* |MetalsImportBuild|
* |MetalsInstall|
* |MetalsInfo|
* |MetalsNewScalaFile|
* |MetalsNewScalaProject|
* |MetalsOpenNewGithubIssue|
* |MetalsOrganizeImports|
* |MetalsQuickWorksheet|
* |MetalsResetChoice|
* |MetalsResetWorkspace|
* |MetalsRestartBuild|
* |MetalsRestartServer|
* |MetalsRunDoctor|
* |MetalsRunScalafix|
* |MetalsRunSingleScalafix|
* |MetalsScanSources|
* |MetalsSelectTestCase|
* |MetalsSelectTestSuite|
* |MetalsShowBuildTargetInfo|
* |MetalsShowCfr|
* |MetalsShowJavap|
* |MetalsShowJavapVerbose|
* |MetalsShowSemanticdbCompact|
* |MetalsShowSemanticdbDetailed|
* |MetalsShowSemanticdbProto|
* |MetalsShowTasty|
* |MetalsStartAmmonite|
* |MetalsStartScalaCli|
* |MetalsStartServer|
* |MetalsStopAmmonite|
* |MetalsStopScalaCli|
* |MetalsSuperMethodHierarchy|
* |MetalsSwitchBsp|
* |MetalsToggleLogs|
* |MetalsUpdate|
* |MetalsZipReports|
*MetalsAnalyzeStacktrace*
MetalsAnalyzeStacktrace Takes the stacktrace from your current register
and sends it to Metals to be analyzed. This will
then create a `.metals/stacktrace.scala` file
which will be populated with code lenses to help
you navigate to the trace location.
*MetalsCompileCancel*
MetalsCompileCancel Cancel any ongoing compilation.
*MetalsCompileCascade*
MetalsCompileCascade Compile the current open file along with all build
targets that depend on it.
*MetalsCompileClean*
MetalsCompileClean Recompile all build targets in this workspace. By
default, Metals compiles the files incrementally.
In case of any compile artifacts corruption this
command might be run to make sure everything is
recompiled correctly.
*MetalsConnectBuild*
MetalsConnectBuild Manually connect to the build server.
*MetalsCopyWorksheetOutput*
MetalsCopyWorksheetOutput Copy the contents of a worksheet to your local
buffer.
*MetalsDisconnectBuild*
MetalsDisconnectBuild Manually disconnect from the build server without
reconnecting.
*MetalsFindInDependencyJars*
MetalsFindInDependencyJars Used to find values in dependency jar files. Note
that this differs from global symbol search in
that it looks through a specific filetype given a
mask. The default mask is `.conf`. This is useful
to search through configuration files that your
dependencies may be bringing in.
*MetalsGenerateBspConfig*
MetalsGenerateBspConfig Checks to see if your build tool can serve as a
BSP server. If so, generate the necessary BSP
config to connect to the server. If there is more
than one build tool for a workspace, you can then
choose the desired one and that one will be used
to generate the config. After the config is
generated, Metals will attempt to auto-connect to
it.
*MetalsGotoSuperMethod*
MetalsGotoSuperMethod Jump to the super method of the current symbol.
*MetalsImportBuild*
MetalsImportBuild Trigger an import for the current workspace.
*MetalsInfo*
MetalsInfo Give info about the currently installed version
of Metals that will be used, and display it in a
floating window. This will also contain the
location of Metals that was installed with
|MetalsInstall|, the location of the
`nvim-metals.log` file, and some helpful links.
*MetalsInstall*
MetalsInstall Install Metals. NOTE that behind the scenes this
calls the exact same function as |MetalsUpdate|.
*MetalsNewScalaFile*
MetalsNewScalaFile Create a new Scala file. This will produce a
prompt for the user to choose what type of file
they'd like (case class, trait, object, etc) and
also prompts for a name.
*MetalsNewScalaProject*
MetalsNewScalaProject Create a new Scala project using one of the
available g8 templates. This includes simple
projects as well as samples for most of the popular
Scala frameworks.
*MetalsOpenNewGithubIssue*
MetalsOpenNewGithubIssue Grab some relevant information from your system
and open a new issue in the Metals GitHub repo
with this information.
NOTE: That this is for Metals-specific bugs. If
you'd like to create an issue for this plusin,
make sure to create it in
`scalameta/nvim-metals`.
*MetalsOrganizeImports*
MetalsOrganizeImports Sends a code action request to Metals to organize
imports. NOTE: that this is blocking, and it has a
timeout of 1000ms.
*MetalsQuickWorksheet*
MetalsQuickWorksheet Creates a worksheet in the current directory that
you're in with the name of the worksheet being the
parent dir.
Example: If you're in
`src/main/scala/example/Main.scala` and you
execute this command the file you'll have created
will be
`src/main/scala/example/example.worksheet.sc`.
*MetalsResetChoice*
MetalsResetChoice ResetChoicePopup command allows you to reset a
decision you made about different settings.
E.g. If you choose to import workspace with sbt
you can decide to reset and change it again.
*MetalsResetWorkspace*
MetalsResetWorkspace Fully clean the workspace and restart the build
server. When things seem to get borked and you
don't know what to do, use this. It's
essentially the same as if you'd do an `rm -rf`
on all the dirs like `.bloop` etc that Metals
creates, as well as restarting whatever build
server you're using.
*MetalsRestartBuild*
MetalsRestartBuild Manually restart the build server.
*MetalsRestartServer*
MetalsRestartServer Restart the Metals server.
*MetalsRunDoctor*
MetalsRunDoctor Run Metals Doctor, which will open a floating
window to show you the status of Metals.
*MetalsRunScalafix*
MetalsRunScalafix Runs all of the Scalafix rules that you have
configured for you current project.
NOTE: that if you're using external Scalafix
rules you'll need to ensure you add them to your
settings table under `scalafixRulesDependencies`.
*MetalsRunSingleScalafix*
MetalsRunSingleScalafix Runs a single Scalafix rules that you have given
or provides you with a list of configured rules to
choose from.
NOTE: that if you're using external Scalafix
rules you'll need to ensure you add them to your
settings table under `scalafixRulesDependencies`.
*MetalsScanSources*
MetalsScanSources Scan all workspaces sources.
*MetalsSelectTestCase*
MetalsSelectTestCase Select the test suite in your workspace to run.
NOTE: this requires additional configuration.
See |metals-nvim-dap|
*MetalsSelectTestSuite*
MetalsSelectTestSuite Select test case from current file to run.
NOTE: this requires additional configuration.
See |metals-nvim-dap|
*MetalsShowBuildTargetInfo*
MetalsShowBuildTargetInfo Will return a list of all the build targets in
your build that you can choose from. Once chosen it
will display all sorts of information about your
build target such as the scalacOptions, the
classpath, etc.
*MetalsShowCfr*
MetalsShowCfr Show the cfr output for the current file.
- https://www.benf.org/other/cfr/
*MetalsShowJavap*
MetalsShowJavap Show the compact output of javap for the given
file you're in.
*MetalsShowJavapVerbose*
MetalsShowJavapVerbose Show the verbose output of javap for the given file
you're in.
*MetalsShowSemanticdbCompact*
MetalsShowSemanticdbCompact Show the compact SemanticDB of the given file you
are in.
*MetalsShowSemanticdbDetailed*
MetalsShowSemanticdbDetailed Show the detailed SemanticDB of the given file you
are in.
*MetalsShowSemanticdbProto*
MetalsShowSemanticdbProto Show the proto SemanticDB of the given file you
are in.
*MetalsShowTasty*
MetalsShowTasty Show the TASTy representation of the current file.
NOTE: This currently only works in Scala 3.
*MetalsStartAmmonite*
MetalsStartAmmonite Start the Ammonite BSP Server.
*MetalsStartScalaCli*
MetalsStartScalaCli Start Scala CLI as a BSP server.
*MetalsStartServer*
MetalsStartServer Start Metals server. Must be in a Scala or sbt file
in a workspace where Metals is not yet started.
*MetalsStopAmmonite*
MetalsStopAmmonite Stop the Ammonite BSP Server.
*MetalsStopScalaCli*
MetalsStopScalaCli Stop the Scala CLI when running as a Build
Server.
*MetalsSuperMethodHierarchy*
MetalsSuperMethodHierarchy Gathers the inheritance hierarchy of a member and
if more than one is found, the user is given a
quick pick option to jump to the point in the
hierarchy tree selected.
*MetalsSwitchBsp*
MetalsSwitchBsp Prompts the user to select a new build server to
connect to. This command does nothing in case there
are less than two installed build servers on the
computer. In case the user has multiple BSP servers
installed then Metals will prompt the user to
select which server to use.
*MetalsToggleLogs*
MetalsToggleLogs Opens the embedded Nvim terminal tailing the
|.metals/metals.log| file in your workspace. If
triggered again, this will either bring you to
the window that has the logs open, or open the
buffer in a split in your current window.
*MetalsUpdate*
MetalsUpdate Update to the latest stable version of Metals or
change versions to the new version you have
defined in your settings table under
`serverVersion`.
NOTE that behind the scenes this calls the same
function as |MetalsInstall|.
*MetalsZipReports*
MetalsZipReports Zip up the icognito repos that are located under
`.metals/.reports/metals` than can be used to
upload with an issue report.
================================================================================
LUA API *metals-lua-api*
The following Lua module functions are exposed for you to use via mappings.
In order to use any of these you'd need to require the module. As an example,
if you wanted to bind the |import_build()| to a mapping, the right hand side of
the mapping would be: >
<cmd>lua require("metals").import_build()<CR>
<
Note: Most of these that are just executing commands that you can
find above in |metals-commands| with more details. Please keep in mind
that here we are trying to unify command names with verb followed by noun.
That's why `nvim-metals` lua commands sometimes differ from metals commands.
*analyze_stacktrace()*
analyze_stacktrace() Use to execute a |metals.analyze-stacktrace| command.
*bare_config()*
bare_config()
Returns an empty config table with empty tables also
set for settings, handlers, and init_options, and
tvp settings. Use this when setting up settings for
`nvim-metals` to pass into |initialize_or_attach()|.
commands() *commands()*
Gives the users all the available |metals-commands|
utilizing |vim.ui.select()|. If you're a telescope
user you can choose to use this with something like
https://github.com/stevearc/dressing.nvim or feel
free to use the built-in telescope extension
|metals-telescope| which just displays things a bit
better since we have more control over using
|vim.ui.select()|. If you're not a telescope user,
then you'll want to use this.
*compile_cancel()*
compile_cancel() Use to execute a |metals.compile-cancel| command.
*compile_cascade()*
compile_cascade() Use to execute a |metals.compile-cascade| command.
*compile_clean()*
compile_clean() Use to execute a |metals.compile-clean| command.
*connect_build()*
connect_build() Use to execute a |metals.build-connect| command.
*copy_worksheet_output()*
copy_worksheet_output() Use to execute a |metals.copy-worksheet-output|
command.
*disconnect_build()*
disconnect_build() Use to execute a |metals.build-disconnect| command.
*generate_bsp_config()*
generate_bsp_config() Use to execute a |metals.generate-bsp-config| command.
*goto_super_method()*
goto_super_method() Use to execute a |metals.goto-super-method| command.
This is the same as triggering the code lens on a
symbol that is overriding another.
*find_in_dependency_jars()*
find_in_dependency_jars() Use to send in a `meatals/findTextInDependencyJars`
request to the server.
*hover_worksheet()*
hover_worksheet({opts}) Use to expand the decoration to show the full hover
message that was returned from the decoration.
Parameter is optional.
Parameters:
{opts} (table) Options that are passed to
|vim.lsp.util.open_floating_preview()|
*import_build()*
import_build() Use to execute a |metals.build-import| command.
*info()*
info() Give info about the currently installed version of
Metals that will be used by `nvim-metals`, the
location of the installed Metals, and the location
of the `nvim-metals.log` file.
*initialize_or_attach()*
initialize_or_attach({config})
This is the main entrypoint into the plugin, and the
way to set up `nvim-metals`. See the example in
|metals-getting-started| for an example.
Parameters:
{config} (table) This config is meant to mimic the
config that is used in the |vim.lsp.start_client()|.
You can visit the help docs of vim to see the full
signature of the config.
There are a couple small differences with this
config table. The first is `root_patterns`, which
is a short way to change way the `root_dir` is
detected by giving it new patterns. The default
`root_patterns` are >
{'build.sbt', 'build.sc', 'build.gradle',
'pom.xml', '.git'}
<
By default, when Metals detects a valid root_dir,
it will check 1 folder up to see if there is a
valid "parent" project above it. If you have a
more complex project with multiple nested sub-
projects, set the `find_root_dir_max_project_nesting`
key to an integer greater than 1.
Ex: Set `find_root_dir_max_project_nesting` to 2 if
this is your project tree:
build.sbt <- this is the desired root
a/
b/
- build.sbt <- subproject, not the desired root
- src/main/scala/Main.scala
If you need even more fine-grained control over
finding your root-dir (in cases where you have very
uncommon build layouts) you can also use the
`find_root_dir` key in the config to provide your
own custom function to find the root dir given a
starting dir and root patterns. _You more than likely
shouldn't need to do this_.
The other small difference is the `settings` key.
Since this is only the config for `nvim-metals` you
don't need to preface your settings object with the
`metals` keyword. You can find more information
about how to set these in |metals-settings|.
NOTE: This function also includes some
metals-specific autocommands
that are given to the `on_attach()` of the config.
NOTE: Keep in mind that there are some other
autocmds that you'll probably want to set up locally
that aren't set by default to ensure features like
document highlighting and code lenses work. Make
sure to check out
|vim.lsp.buf.document_highlight()|,
|vim.lsp.buf.clear_references()|, and
|vim.lsp.codelens.refresh()|.
*install_or_update()*
install_or_update() Install Metals if it doesn't exist or update to the
latest stable version or version set if you have a
`serverVersion` entry in your config table.
*new_java_file()*
new_java_file({directory_uri_opt}, {name_opt}, {file_type_option})
Use to execute a |metals.new-java-file| command. All
of the parameters are optional. If they are not
provided you will be prompted for them.
Parameters:
{directory_uri_opt} (string) directory that you'd
like the new file to be created in.