Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: obey hover markup kind capability #6303

Merged
merged 11 commits into from
Apr 23, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import java.{util => ju}

import scala.meta.internal.metals.ClasspathSearch
import scala.meta.internal.metals.WorkspaceSymbolQuery
import scala.meta.pc.ContentType
import scala.meta.pc.ParentSymbols
import scala.meta.pc.SymbolDocumentation
import scala.meta.pc.SymbolSearch
Expand All @@ -26,6 +27,12 @@ class ClasspathOnlySymbolSearch(classpath: ClasspathSearch)
): Optional[SymbolDocumentation] =
Optional.empty()

override def documentation(
symbol: String,
parents: ParentSymbols,
docstringContentType: ContentType,
): Optional[SymbolDocumentation] = Optional.empty()

def definition(symbol: String, source: URI): ju.List[Location] =
ju.Collections.emptyList()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package scala.meta.internal.metals
import scala.meta.internal.metals.Configs.GlobSyntaxConfig
import scala.meta.internal.metals.config.DoctorFormat
import scala.meta.internal.metals.config.StatusBarState
import scala.meta.pc.ContentType

import org.eclipse.lsp4j.ClientCapabilities
import org.eclipse.lsp4j.InitializeParams
Expand Down Expand Up @@ -161,6 +162,18 @@ final class ClientConfiguration(
} yield true
}.getOrElse(false)

def hoverContentType(): ContentType =
(for {
capabilities <- clientCapabilities
textDocumentCapabilities <- Option(capabilities.getTextDocument())
hoverCapabilities <- Option(textDocumentCapabilities.getHover())
contentTypes <- Option(hoverCapabilities.getContentFormat())
} yield {
if (contentTypes.contains(ContentType.MARKDOWN.toString()))
ContentType.MARKDOWN
else ContentType.PLAINTEXT
}).getOrElse(ContentType.MARKDOWN)

def isTreeViewProvider(): Boolean =
extract(
initializationOptions.treeViewProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ class CompilerConfiguration(
initializeParams.supportsCompletionSnippets,
_isStripMarginOnTypeFormattingEnabled =
() => userConfig().enableStripMarginOnTypeFormatting,
hoverContentType = config.hoverContentType(),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,9 @@ class Compilers(
token: CancelToken,
): Future[Option[HoverSignature]] = {
withPCAndAdjustLsp(params) { (pc, pos, adjust) =>
pc.hover(CompilerRangeParamsUtils.offsetOrRange(pos, token))
.asScala
pc.hover(
CompilerRangeParamsUtils.offsetOrRange(pos, token)
).asScala
.map(_.asScala.map { hover => adjust.adjustHoverResp(hover) })
}
}.getOrElse(Future.successful(None))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ final class InlayHintResolveProvider(
)
compilers.hover(hoverParams, token).map { hover =>
hover
.foreach(h => labelPart.setTooltip(h.toLsp().getContents().getRight()))
.foreach(h =>
labelPart.setTooltip(
h.toLsp().getContents().getRight()
)
)
labelPart
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import scala.collection.concurrent.TrieMap
import scala.meta.internal.metals.MetalsEnrichments._
import scala.meta.internal.mtags.Mtags
import scala.meta.io.AbsolutePath
import scala.meta.pc.ContentType
import scala.meta.pc.ParentSymbols
import scala.meta.pc.SymbolDocumentation
import scala.meta.pc.SymbolSearch
Expand Down Expand Up @@ -40,7 +41,14 @@ class MetalsSymbolSearch(
symbol: String,
parents: ParentSymbols,
): Optional[SymbolDocumentation] =
docs.documentation(symbol, parents)
documentation(symbol, parents, ContentType.MARKDOWN)

override def documentation(
symbol: String,
parents: ParentSymbols,
contentType: ContentType,
tgodzik marked this conversation as resolved.
Show resolved Hide resolved
): Optional[SymbolDocumentation] =
docs.documentation(symbol, parents, contentType)

def definition(symbol: String, source: URI): ju.List[Location] = {
val sourcePath = Option(source).map(AbsolutePath.fromAbsoluteUri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import scala.meta.internal.mtags.Mtags
import scala.meta.internal.mtags.OnDemandSymbolIndex
import scala.meta.internal.parsing.Trees
import scala.meta.io.AbsolutePath
import scala.meta.pc.ContentType
import scala.meta.pc.ParentSymbols
import scala.meta.pc.SymbolDocumentation
import scala.meta.pc.SymbolSearch
Expand Down Expand Up @@ -64,12 +65,21 @@ class StandaloneSymbolSearch(
def documentation(
symbol: String,
parents: ParentSymbols,
): ju.Optional[SymbolDocumentation] =
documentation(symbol, parents, docstringContentType = ContentType.MARKDOWN)

override def documentation(
symbol: String,
parents: ParentSymbols,
docstringContentType: ContentType,
): ju.Optional[SymbolDocumentation] =
docs
.documentation(symbol, parents)
.documentation(symbol, parents, docstringContentType)
.asScala
.orElse(
workspaceFallback.flatMap(_.documentation(symbol, parents).asScala)
workspaceFallback.flatMap(
_.documentation(symbol, parents, docstringContentType).asScala
)
)
.asJava

Expand Down
16 changes: 16 additions & 0 deletions mtags-interfaces/src/main/java/scala/meta/pc/ContentType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package scala.meta.pc;

public enum ContentType {
MARKDOWN("markdown"),
PLAINTEXT("plaintext");

private final String name;
ContentType(String name) {
this.name = name;
}

@Override
public String toString() {
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ public interface HoverSignature {
Optional<String> signature();
Optional<Range> getRange();
HoverSignature withRange(Range range);
default ContentType contentType() {
return ContentType.MARKDOWN;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,16 @@ public abstract CompletableFuture<List<TextEdit>> convertToNamedArguments(Offset
public abstract CompletableFuture<List<Diagnostic>> didChange(VirtualFileParams params);

/**
* Returns decorations for missing type adnotations, inferred type parameters, implicit parameters and conversions.
* Returns decorations for missing type adnotations, inferred type parameters,
* implicit parameters and conversions.
*/
public CompletableFuture<List<InlayHint>> inlayHints(InlayHintsParams params) {
return CompletableFuture.completedFuture(Collections.emptyList());
}

/**
* Returns decorations for missing type adnotations, inferred type parameters, implicit parameters and conversions.
* Returns decorations for missing type adnotations, inferred type parameters,
* implicit parameters and conversions.
*/
public CompletableFuture<List<SyntheticDecoration>> syntheticDecorations(SyntheticDecorationsParams params) {
return CompletableFuture.completedFuture(Collections.emptyList());
Expand Down
Loading
Loading