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

Remove deprecated code #96

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"eslint.packageManager": "yarn",
"search.exclude": {
"**/node_modules": true,
"**/lib": true,
"**/coverage": true
},
"editor.insertSpaces": true,
"files.trimTrailingWhitespace": true,
"[typescript]": {
"editor.tabSize": 4
},
"typescript.tsdk": "node_modules/typescript/lib",
"files.trimTrailingWhitespace": true,
"typescript.enablePromptUseWorkspaceTsdk": true,
}
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/eclipse/sprotty-vscode)
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/eclipse/sprotty-vscode)

# sprotty-vscode

Expand All @@ -16,7 +16,7 @@ Also contains an example extension for a domain-specific language for statemachi

## Architecture

In VS Code, extensions can contribute new UI components using a webview. Webviews communicate with the extension using the [`postMessage`](https://code.visualstudio.com/api/extension-guides/webview#passing-messages-from-an-extension-to-a-webview) API. The [`WebviewPanelManager`](./packages/sprotty-vscode/src/webview-panel-manager.ts) uses this to send and receive Sprotty Actions to and from a [`WebviewEndpoint`](./packages/sprotty-vscode/src/webview-endpoint.ts). The latter runs a webpacked `bundle.js` that contains the Sprotty diagram code.
In VS Code, extensions can contribute new UI components using a webview. Webviews communicate with the extension using the [`vscode-messenger`](https://github.com/TypeFox/vscode-messenger) library. The [`WebviewPanelManager`](./packages/sprotty-vscode/src/webview-panel-manager.ts) uses this to send and receive Sprotty Actions to and from a [`WebviewEndpoint`](./packages/sprotty-vscode/src/webview-endpoint.ts). The latter runs a webpacked `bundle.js` that contains the Sprotty diagram code.

![Architecture Diagram](images/architecture.png)

Expand All @@ -25,15 +25,19 @@ If your extension provides a language, you can include a [Sprotty-enhanced langu
## Contents

The repo is structured as follows
- `example/`: an example using an Xtext-based Language Server and with Sprotty visualization.
- `sprotty-vscode-extension/`: library code for the VSCode extension.
- `sprotty-vscode-protocol/`: common protocol classes for the communication between the extension and the webview.
- `sprotty-vscode-webview/`: library code for the script that is run in the webview.
- `examples`: an example Sprotty visualization using a [Langium](https://langium.org/)-based Language Server.
- `packages/sprotty-vscode`: library code for the VSCode extension.
- `packages/sprotty-vscode-protocol`: common protocol classes for the communication between the extension and the webview.
- `packages/sprotty-vscode-webview`: library code for the script that is run in the webview.

## Development

Compile the library code and the examples
Compile the library code and the examples:
```
examples/states-xtext/language-server/gradlew -p examples/states-xtext/language-server/ build && yarn
yarn
```

If you also want to use the older Xtext-based example, you need to run this command before `yarn`:
```
./examples/states-xtext/language-server/gradlew -p examples/states-xtext/language-server/ build
```
31 changes: 0 additions & 31 deletions packages/sprotty-vscode/src/action-handler.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/sprotty-vscode/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
export * from './default-contributions';
export * from './sprotty-editor-provider';
export * from './sprotty-view-provider';
export * from './sprotty-vscode-extension';
export * from './sprotty-webview';
export * from './webview-endpoint';
export * from './webview-panel-manager';
export * from './webview-utils';
Expand Down
1 change: 0 additions & 1 deletion packages/sprotty-vscode/src/lsp/editing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@

export * from './lsp-label-edit-action-handler';
export * from './workspace-edit-action-handler';
export * from './sprotty-lsp-edit-vscode-extension';
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2020 TypeFox and others.
* Copyright (c) 2020-2023 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -14,16 +14,12 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { Action } from 'sprotty-protocol';
import { LspLabelEditAction } from 'sprotty-vscode-protocol/lib/lsp/editing';
import * as vscode from 'vscode';
import {
CompletionItem, CompletionItemKind, CompletionList, CompletionRequest, LanguageClient,
PrepareRenameRequest, RenameParams, RenameRequest, TextDocumentPositionParams
CompletionItem, CompletionItemKind, CompletionRequest, PrepareRenameRequest, RenameParams,
RenameRequest, TextDocumentPositionParams
} from 'vscode-languageclient/node';
import { ActionHandler } from '../../action-handler';
import { SprottyLspVscodeExtension } from '../sprotty-lsp-vscode-extension';
import { SprottyWebview } from '../../sprotty-webview';
import { convertPosition, convertUri, convertWorkspaceEdit, convertRange } from '../lsp-utils';
import { LspWebviewEndpoint } from '../lsp-webview-endpoint';

Expand Down Expand Up @@ -91,93 +87,3 @@ async function renameElement(action: LspLabelEditAction, endpoint: LspWebviewEnd
}
}
}

/**
* @deprecated Use `addLspLabelEditActionHandler` instead.
*/
export class LspLabelEditActionHandler implements ActionHandler {

readonly kind = LspLabelEditAction.KIND;

constructor(readonly webview: SprottyWebview) {
if (!(webview.extension instanceof SprottyLspVscodeExtension))
throw new Error('LspLabelEditActionHandler must be initialized with a SprottyLspWebview');
}

async handleAction(action: Action): Promise<boolean> {
if (LspLabelEditAction.is(action)) {
switch (action.editKind) {
case 'xref': return this.chooseCrossReference(action);
case 'name': return this.renameElement(action);
}
}
return false;
}

protected get languageClient(): LanguageClient {
return (this.webview.extension as SprottyLspVscodeExtension).languageClient;
}

async chooseCrossReference(action: LspLabelEditAction): Promise<boolean> {
const completions = await this.languageClient.sendRequest(CompletionRequest.type, {
textDocument: { uri: action.location.uri },
position: convertPosition(action.location.range.start)
});
if (completions) {
const completionItems = ((completions as any)["items"])
? (completions as CompletionList).items
: completions as CompletionItem[];

const quickPickItems = this.filterCompletionItems(completionItems)
.map(completionItem => {
return <vscode.QuickPickItem> {
label: completionItem.textEdit!.newText,
value: completionItem
};
});
const pick = await vscode.window.showQuickPick(quickPickItems);
if (pick) {
const pickedCompletionItem = (pick as any).value as CompletionItem;
if (pickedCompletionItem.textEdit) {
const workspaceEdit = new vscode.WorkspaceEdit();
const textEdit = vscode.TextEdit.replace(convertRange(action.location.range), pickedCompletionItem.textEdit.newText);
workspaceEdit.set(convertUri(action.location.uri), [ textEdit ]);
return vscode.workspace.applyEdit(workspaceEdit);
}
}
}
return false;
}

protected filterCompletionItems(items: CompletionItem[]): CompletionItem[] {
return items.filter(item => item.kind === CompletionItemKind.Reference);
}

async renameElement(action: LspLabelEditAction): Promise<boolean> {
const canRename = await this.languageClient.sendRequest(PrepareRenameRequest.type, <TextDocumentPositionParams> {
textDocument: {
uri: action.location.uri
},
position: action.location.range.start
});
if (canRename) {
const newName = await vscode.window.showInputBox({
prompt: 'Enter new name',
placeHolder: 'new name',
value: action.initialText
});
if (newName) {
const workspaceEdit = await this.languageClient.sendRequest(RenameRequest.type, <RenameParams> {
textDocument: {
uri: action.location.uri
},
position: action.location.range.start,
newName
});
if (workspaceEdit)
return vscode.workspace.applyEdit(convertWorkspaceEdit(workspaceEdit));
}
}
return false;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { Action } from 'sprotty-protocol';
import { WorkspaceEditAction } from 'sprotty-vscode-protocol/lib/lsp/editing';
import * as vscode from 'vscode';
import { ActionHandler } from '../../action-handler';
import { convertWorkspaceEdit } from '../lsp-utils';
import { LspWebviewEndpoint } from '../lsp-webview-endpoint';

Expand All @@ -27,16 +25,3 @@ export function addWorkspaceEditActionHandler(endpoint: LspWebviewEndpoint): voi
};
endpoint.addActionHandler(WorkspaceEditAction.KIND, handler);
};

/**
* @deprecated Use `addWorkspaceEditActionHandler` instead.
*/
export class WorkspaceEditActionHandler implements ActionHandler {
readonly kind = WorkspaceEditAction.KIND;

async handleAction(action: Action): Promise<boolean> {
if (WorkspaceEditAction.is(action))
await vscode.workspace.applyEdit(convertWorkspaceEdit(action.workspaceEdit));
return false;
}
}
2 changes: 0 additions & 2 deletions packages/sprotty-vscode/src/lsp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,3 @@ export * from './lsp-utils';
export * from './lsp-webview-endpoint';
export * from './lsp-webview-panel-manager';
export * from './protocol';
export * from './sprotty-lsp-webview';
export * from './sprotty-lsp-vscode-extension';
80 changes: 0 additions & 80 deletions packages/sprotty-vscode/src/lsp/sprotty-lsp-vscode-extension.ts

This file was deleted.

Loading
Loading