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

Protocol extension to drive UI components #1579

Open
michelkaporin opened this issue Nov 7, 2022 · 7 comments
Open

Protocol extension to drive UI components #1579

michelkaporin opened this issue Nov 7, 2022 · 7 comments
Labels
feature-request Request for new features or functionality new request
Milestone

Comments

@michelkaporin
Copy link

👋 Have there been any attempts to provide an extension to the protocol to standardise UI contribution for LSP-based extension developers?

If not, is this planned or would it be possible to standardise it, should such an attempt be made?

Context
The benefit of language server is that it's code editor/IDE independent. UI components are normally editor-specific, however there are certain presentational layer elements that are shared by many code editors. For instance, tree view components can often be implemented by different vendors (e.g. editors often have "File Outline" as tree view).

As an extension developer, it's hard to maintain such UIs per each IDE that are enabled via LSP. Another example of such is web view UI component, which allows extension developers to create fully customisable views.

@dbaeumer
Copy link
Member

dbaeumer commented Nov 8, 2022

See also #1164

@dbaeumer dbaeumer added the feature-request Request for new features or functionality label Nov 8, 2022
@dbaeumer dbaeumer added this to the Backlog milestone Nov 8, 2022
@puremourning
Copy link

we need to be cautious of the inner platform effect here.

we also need to be careful not to make features that rely on capabilities of certain editors (such as having a "tree view"). It seems better to me for LSP to concentrate on abstractions, rather than complexities of concrete UI concepts.

@DanTup
Copy link
Contributor

DanTup commented Nov 28, 2022

I posted some notes about what we've started trying out with Dart here:

#1164 (comment)

It's intended to be editor-agnostic. The editor tells the server what kinds of parameters it can prompt the user for and they're just replaced into the arguments of the command that will be executed (by middleware in the VS Code extension, but it's intended that other editors extensions could do the same with whatever appropriate mechanisms they have for collecting input from a user).

@puremourning
Copy link

I still think that a better API doesn't ask anyone to "prompt" the user for anything. Rather a refactoring states its parameters, their types, say, and the editor/user/script/plugin/bot determines how to provide those to the server. The corollary is the rename request (which is a sort of special-cased code-action), where it has a defined parameter ("new name") and clients surface how to provide that however they choose. this comment applies to this issue and #1164

@DanTup
Copy link
Contributor

DanTup commented Nov 28, 2022

@puremourning that's basically what I posted. The API above does not have the server drive any prompts - it provides the user with parameters and their kinds, and it's up to the client to handle getting user input and replacing the values in the arguments sent to the command.

The enumeration of those parameters and sequential prompting is entirely VS Code-specific stuff in some middleware. A client that supports dialogs could easily show a single dialog that collects all of that info in one step.

@puremourning
Copy link

The API above does not have the server drive any prompts - it provides the user with parameters and their kinds, and it's up to the client to handle getting user input and replacing the values in the arguments sent to the command.

Great - SGTM in principle! Sorry I sort of got all confused by the VScode-specific parts of your post over there :).

@DanTup
Copy link
Contributor

DanTup commented Nov 28, 2022

Yeah sorry, the links to code were all in middleware because there isn't so much in the way of "spec" for the protocol.

The JSON for a CodeAction looks something like this:

{
	"kind": "refactor",
	"title": "Move 'main' to file",
	"command": {
		"arguments": [
			// For Dart, we generally pass arguments as an object so we can
			// provide names, so the arguments list here is a single item
			{
				// These arguments are not defined by parameters but are fixed
				"filePath": "/Users/danny/Desktop/dart_sample/bin/main.dart",
				"selectionOffset": 7,
				"selectionLength": 0,
				// These additional "arguments" can be overwritten by user-provided values
				// using the info in data.parameters 
				"arguments": [
					"file:///Users/danny/Desktop/dart_sample/bin/main.dart"
				]
			}
		],
		"command": "move_top_level_to_file",
		"title": "Move 'main' to file"
	},
	"data": {
		// These parameters map to "arguments" above
		"parameters": [
			{
				"kind": "saveUri",
				"parameterTitle": "Select a file to move to",
				"parameterLabel": "Move to:",
				"defaultValue": "file:///Users/danny/Desktop/dart_sample/bin/main.dart",
				"actionLabel": "Move",
				"filters": {
					"Dart": [
						"dart"
					]
				}
			}
		]
	}
}

The client uses data.parameters to drive any UI and replace values into the arguments list before the command is sent back to the server for execution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality new request
Projects
None yet
Development

No branches or pull requests

4 participants