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

Hover / Suggest inconsistency: Plaintext Linebreak #79840

Closed
octref opened this issue Aug 26, 2019 · 8 comments
Closed

Hover / Suggest inconsistency: Plaintext Linebreak #79840

octref opened this issue Aug 26, 2019 · 8 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug editor-hover Editor mouse hover suggest IntelliSense, Auto Complete verification-steps-needed Steps to verify are needed for verification verified Verification succeeded

Comments

@octref
Copy link
Contributor

octref commented Aug 26, 2019

Split from #78718:

Plaintext Linebreak

const markupContent: MarkupContent =  {
	kind: 'plaintext',
	value: 'foo\nbar'
};

image

@octref octref added bug Issue identified by VS Code Team member as probable bug ux User experience issues suggest IntelliSense, Auto Complete editor-hover Editor mouse hover labels Aug 26, 2019
@octref octref added this to the September 2019 milestone Aug 26, 2019
@octref octref self-assigned this Aug 26, 2019
@octref octref removed the ux User experience issues label Sep 4, 2019
@octref
Copy link
Contributor Author

octref commented Sep 17, 2019

The problem comes from our API:

vscode.d.ts:

type MarkedString = MarkdownString | string | { language: string; value: string }

class CompletionItem {
  documentation?: string | MarkdownString
}
class Hover {
  contents: MarkedString[]
}

Observations:

  • 'foo' as CompletionItem#documentation would be rendered as plaintext
  • ['foo'] as Hover#contents would be rendered as markdown
  • Completion can rendered either Markdown or Plaintext. Hover can't.

This somewhat makes sense, since string is explicitly an type allowed on CompletionItem#documentation, and the string of 'foo' is interpreted as a subtype of MarkedString in Hover#contents.

However in LSP we have:

type MarkupKind = 'plaintext' | 'markdown'
interface MarkupContent {
  kind: MarkupKind
  value: string
}
interface Hover {
  contents: MarkupContent | MarkedString | MarkedString[]
}
interface CompletionItem {
  documentation?: string | MarkupContent
}

Observations:

  • Both 'foo' and { kind: 'plaintext': value: 'foo' } as CompletionItem#documentation would be rendered as plaintext
  • Both 'foo' and { kind: 'plaintext': value: 'foo' } as Hover#contents would be rendered as markdown.
  • foo as as Hover#contents is subtype of MarkedString, so it's fine if it's rendered as Markdown
  • { kind: 'plaintext': value: 'foo' } as Hover#contents rendered as Markdown doesn't make sense and is inconsistent with CompletionItem#documentation.

We can fix this by allowing string in Hover#contents, like:

class Hover {
  contents: (MarkedString | string)[]
}

for VS Code API, and make LSP node library adopt it.

@jrieken and @dbaeumer, what's your thoughts?

@dbaeumer
Copy link
Member

I do see the problem that we don't support string type directly in Hover however it is supported through MarkdownString.appendText which to my understanding adds plain text to the MarkdownString. I would not add string to Hover.contents. I would rather deprecate string from CompletionItem#documentation

For the describe problem with the line break \n I would fix this in the converter in the LSP client here: https://github.com/Microsoft/vscode-languageserver-node/blob/master/client/src/protocolConverter.ts#L307

@octref
Copy link
Contributor Author

octref commented Sep 20, 2019

I'm wondering if this change should happen in the LS client library or vscode side, since MarkdownString.appendText('\n') should append \n\n if properly escaped. And MarkedString.appendText does advertise "escaping":

https://github.com/microsoft/vscode/blob/master/src/vs/base/common/htmlContent.ts#L25

	export class MarkdownString {
		/**
		 * Appends and escapes the given string to this markdown string.
		 * @param value Plain text.
		 */
		appendText(value: string): MarkdownString;
	}

@dbaeumer
Copy link
Member

@octref that would even be better. Lets see what @jrieken thinks.

@jrieken
Copy link
Member

jrieken commented Sep 30, 2019

👍 for fixing this in appendText

octref added a commit that referenced this issue Sep 30, 2019
@octref octref modified the milestones: October 2019, September 2019 Sep 30, 2019
@octref octref closed this as completed in eb5ec0f Sep 30, 2019
@dbaeumer
Copy link
Member

dbaeumer commented Oct 1, 2019

@octref nice!

@dbaeumer
Copy link
Member

dbaeumer commented Oct 3, 2019

Doesn't work for me.

I think the change also needs to be done here: https://github.com/Microsoft/vscode/blob/master/src/vs/workbench/api/common/extHostTypes.ts#L1230

@dbaeumer dbaeumer reopened this Oct 3, 2019
@dbaeumer dbaeumer added the verification-found Issue verification failed label Oct 3, 2019
@octref
Copy link
Contributor Author

octref commented Oct 3, 2019

Good catch. My bad.

@octref octref removed the verification-found Issue verification failed label Oct 3, 2019
@octref octref closed this as completed in 355676f Oct 3, 2019
@roblourens roblourens added verified Verification succeeded verification-steps-needed Steps to verify are needed for verification and removed verified Verification succeeded labels Oct 4, 2019
@mjbvz mjbvz added the verified Verification succeeded label Oct 4, 2019
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug editor-hover Editor mouse hover suggest IntelliSense, Auto Complete verification-steps-needed Steps to verify are needed for verification verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

5 participants