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

Compatibility with statically typed languages #39

Closed
spoenemann opened this issue Jul 22, 2016 · 13 comments
Closed

Compatibility with statically typed languages #39

spoenemann opened this issue Jul 22, 2016 · 13 comments

Comments

@spoenemann
Copy link
Contributor

Some parts of the protocol cannot be implemented properly in statically typed languages such as Java. Examples:

  • Completion Request response result: CompletionItem[] | CompletionList
  • Hover: type MarkedString = string | { language: string; value: string };

Of course this can be handled during the conversion between JSON and the specific Java data structures. But wouldn't it be better to drop some flexibility in favor of more explicit typing, so this kind of conversion would not be necessary? For example, with a JSON library such as Gson most of the protocol parsing and serialization can be done with the generic capabilities of the library, but ambiguities such as those mentioned above require to implement special cases for the respective types.

@david-driscoll
Copy link

I would support this breaking change, to make things more consistent.

@dbaeumer
Copy link
Member

Point well taken. Would a return type of the form

{
    items: CompletionItem[];
    list: CompletionList
}

Work for you ?

@dbaeumer dbaeumer added this to the 3.0 milestone Aug 18, 2016
@Seairth
Copy link

Seairth commented Aug 19, 2016

In this case, just return a CompletionList. It already contains CompletionItem[]. You could also make CompletionList.isIncomplete optional to ease migration.

@akosyakov
Copy link
Contributor

@dbaeumer What about MarkedString, how will it be modeled?

kaloyan-raev added a commit to kaloyan-raev/php-language-server that referenced this issue Sep 13, 2016
As discussed in
microsoft/language-server-protocol#39
statically typed languages like Java do not support mixed return types,
which in the case of Completion Request is `CompletionItem[] |
CompletionList`.

Thus Typefox - the Java client of the language server protocol - accepts
only `CompletionList`, which contains `CompletionItem[]`.

In order to work with Eclipse Che and other IDEs using the Typefox
client, the Completion Request handler in the PHP language server should
return `CompletionList` instead of `CompletionItems[]`.
@spoenemann
Copy link
Contributor Author

I would vote for dropping the simple string option:

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

@akosyakov
Copy link
Contributor

@spoenemann string and { language, value } were handled differently, i.e. string is rendered as markdown and a pair as source with a syntax highlighting. if it is still true just dropping string won't work, whether MarkedString is markdown or source should be explicitly communicated.

@akosyakov
Copy link
Contributor

akosyakov commented Oct 9, 2016

Actually { language: string; value: string }; can be replaced by string: https://github.com/Microsoft/vscode/blob/c67ef57cda90b5f28499646f7cc94e8dcc5b0586/src/vs/base/browser/htmlContentRenderer.ts#L83, so we can use plain strings in the general case.

@mickaelistria
Copy link

I support @spoenemann here on the idea of dropping the direct string in a newer version of the protocol. It makes parsers more complex without adding much value.
Instead the current behaviour of an untyped MarkedString could happen if language is not set, in which case it's up to the client to decide how to handle it. Ideally, the absence of language on a MarkedString should resolve as plain text, and markdown or html should always be added as a language. Or, if it's worth saving a few bytes, the language server ServerCapabilities element could define a default language once, that will be used by clients whenever the language of MarkedString is not set.

@felixfbecker
Copy link

@mickaelistria You can't use a MarkedString with language set to markdown to get the rendered markdown, that would result in actual syntax highlighting for the markdown code. The cleanest would be to just allow a markdown string, but that would require every client to have a markdown parser. Or he could just display the plain markdown code of course, since MD is designed to be readable even in text form. It can also contain HTML.

@spoenemann
Copy link
Contributor Author

In LSP4J we have solved this issue with an Either type, so from the Java perspective we can close this.

@dbaeumer
Copy link
Member

@spoenemann noticed that my Java skills got a little rusty. Would this be a solution for C# as well ?

@spoenemann
Copy link
Contributor Author

Probably yes, provided you can customize the JSON input / output. For Java we use the Gson library and we implemented a type adapter for Either.

@dbaeumer
Copy link
Member

Given were we are with the protocol I think we can't break this right now. I try to make things not worse for statically types languages, but the priority right now is to now break existing clients.

I will close this issue since I don't see us acting (by breaking) on this in the next 6 - 12 months. Please ping if you think otherwise.

@dbaeumer dbaeumer removed this from the 4.0 milestone Nov 20, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants