Skip to content

Commit 1013f32

Browse files
authored
feat: add diagnostic checking and workspace file opening support (#658)
## Problem No protocol support is available for Flare to get specific files' diagnostics information and open certain files's editors in VSC SIde ## Solution Add the protocol support - Add CheckDiagnosticsRequestType for checking file diagnostics - Add openWorkspaceFileRequestType for opening workspace files - Update base-runtime and standalone to support new LSP methods - Add type definitions for CheckDiagnosticsParams/Result and OpenWorkspaceFileParams/Result - Enable language servers to request diagnostic information from IDEs - Enable language servers to open files in the workspace programmatically <!--- REMINDER: - Read CONTRIBUTING.md first. - Add test coverage for your changes. - Link to related issues/commits. - Testing: how did you test your changes? - Screenshots if applicable --> ## License By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 6480d22 commit 1013f32

File tree

8 files changed

+77
-2
lines changed

8 files changed

+77
-2
lines changed

runtimes/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,18 @@ The server runtime implementation acts as a proxy for LSP methods, which means i
3131
| onInlineCompletion | Yes | Provide list of inline completion suggestions from the Server |
3232
| onExecuteCommand | Yes | Executes a custom command provided by the Server. Servers are advised to document custom commands they support in the package README. |
3333

34+
##### LSP Window
35+
36+
| Description | Method | Params | Method type | Response Type |
37+
| ------------------------------------ | --------------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------- | --------------- |
38+
| Request to check diagnostics for specified files | `aws/checkDiagnostics` | `CheckDiagnosticsParams` | [Request](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) Server to Client | `CheckDiagnosticsResult` |
39+
3440
##### LSP Workspace
3541

3642
| Description | Method | Params | Method type | Response Type |
3743
| ------------------------------------ | --------------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------- | --------------- |
3844
| Request to select workspace item (folder, file) with the selected items returned | `aws/selectWorkspaceItem` | `SelectWorkspaceItemParams` | [Request](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) Server to Client | `SelectWorkspaceItemResult` |
45+
| Request to open a file in the workspace programmatically | `aws/openWorkspaceFile` | `OpenWorkspaceFileParams` | [Request](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#requestMessage) Server to Client | `OpenWorkspaceFileResult` |
3946
| Sent notification to open file differences for the new file content. Supports new, updated or removed files. | `aws/openFileDiff` | `OpenFileDiffParams` | [Notification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) Server to Client | n/a |
4047
| Sent notification that file was copied from old to new path using file system operation. | `aws/didCopyFile` | `CopyFileParams` | [Notification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) Server to Client | n/a |
4148
| Sent notification that content was written to file using file system operation. | `aws/didWriteFile` | `FileParams` | [Notification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage) Server to Client | n/a |

runtimes/protocol/window.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import {
66
ShowOpenDialogResult,
77
ShowOpenDialogParams,
88
SHOW_OPEN_FILE_DIALOG_REQUEST_METHOD,
9+
CHECK_DIAGNOSTICS_REQUEST_METHOD,
10+
CheckDiagnosticsParams,
11+
CheckDiagnosticsResult,
912
} from './lsp'
1013

1114
/**
@@ -27,3 +30,11 @@ export const ShowOpenDialogRequestType = new ProtocolRequestType<
2730
void,
2831
void
2932
>(SHOW_OPEN_FILE_DIALOG_REQUEST_METHOD)
33+
34+
export const CheckDiagnosticsRequestType = new ProtocolRequestType<
35+
CheckDiagnosticsParams,
36+
CheckDiagnosticsResult,
37+
never,
38+
void,
39+
void
40+
>(CHECK_DIAGNOSTICS_REQUEST_METHOD)

runtimes/protocol/workspace.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import {
88
FileParams,
99
OPEN_FILE_DIFF_NOTIFICATION_METHOD,
1010
OpenFileDiffParams,
11+
OPEN_WORKSPACE_FILE_REQUEST_METHOD,
12+
OpenWorkspaceFileParams,
13+
OpenWorkspaceFileResult,
1114
ProtocolNotificationType,
1215
ProtocolRequestType,
1316
SELECT_WORKSPACE_ITEM_REQUEST_METHOD,
@@ -46,3 +49,11 @@ export const didAppendFileNotificationType = new ProtocolNotificationType<FilePa
4649
export const didCreateDirectoryNotificationType = new ProtocolNotificationType<FileParams, void>(
4750
DID_CREATE_DIRECTORY_NOTIFICATION_METHOD
4851
)
52+
53+
export const openWorkspaceFileRequestType = new ProtocolRequestType<
54+
OpenWorkspaceFileParams,
55+
OpenWorkspaceFileResult,
56+
never,
57+
void,
58+
void
59+
>(OPEN_WORKSPACE_FILE_REQUEST_METHOD)

runtimes/runtimes/base-runtime.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ import { Service } from 'aws-sdk'
102102
import { ServiceConfigurationOptions } from 'aws-sdk/lib/service'
103103
import { getClientInitializeParamsHandlerFactory } from './util/lspCacheUtil'
104104
import { newAgent } from './agent'
105-
import { ShowSaveFileDialogRequestType } from '../protocol/window'
105+
import { ShowSaveFileDialogRequestType, CheckDiagnosticsRequestType } from '../protocol/window'
106+
import { openWorkspaceFileRequestType } from '../protocol/workspace'
106107
import { joinUnixPaths } from './util/pathUtil'
107108
import { editCompletionRequestType } from '../protocol/editCompletions'
108109

@@ -273,13 +274,15 @@ export const baseRuntime = (connections: { reader: MessageReader; writer: Messag
273274
onUpdateConfiguration: lspServer.setUpdateConfigurationHandler,
274275
selectWorkspaceItem: params => lspConnection.sendRequest(selectWorkspaceItemRequestType.method, params),
275276
openFileDiff: params => lspConnection.sendNotification(openFileDiffNotificationType.method, params),
277+
openWorkspaceFile: params => lspConnection.sendRequest(openWorkspaceFileRequestType.method, params),
276278
},
277279
window: {
278280
showMessage: params => lspConnection.sendNotification(ShowMessageNotification.method, params),
279281
showMessageRequest: params => lspConnection.sendRequest(ShowMessageRequest.method, params),
280282
showDocument: params => lspConnection.sendRequest(ShowDocumentRequest.method, params),
281283
showSaveFileDialog: params => lspConnection.sendRequest(ShowSaveFileDialogRequestType.method, params),
282284
showOpenDialog: params => lspConnection.sendRequest(ShowOpenDialogRequestType.method, params),
285+
checkDiagnostics: params => lspConnection.sendRequest(CheckDiagnosticsRequestType.method, params),
283286
},
284287
publishDiagnostics: params => lspConnection.sendNotification(PublishDiagnosticsNotification.method, params),
285288
sendProgress: <P>(type: ProgressType<P>, token: ProgressToken, value: P) => {

runtimes/runtimes/standalone.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import {
3434
ShowOpenDialogRequestType,
3535
stsCredentialChangedRequestType,
3636
getMfaCodeRequestType,
37+
CheckDiagnosticsParams,
38+
OpenWorkspaceFileParams,
3739
} from '../protocol'
3840
import { ProposedFeatures, createConnection } from 'vscode-languageserver/node'
3941
import {
@@ -91,7 +93,8 @@ import { getTelemetryLspServer } from './util/telemetryLspServer'
9193
import { getClientInitializeParamsHandlerFactory } from './util/lspCacheUtil'
9294
import { makeProxyConfigv2Standalone, makeProxyConfigv3Standalone } from './util/standalone/proxyUtil'
9395
import { newAgent } from './agent'
94-
import { ShowSaveFileDialogRequestType } from '../protocol/window'
96+
import { ShowSaveFileDialogRequestType, CheckDiagnosticsRequestType } from '../protocol/window'
97+
import { openWorkspaceFileRequestType } from '../protocol/workspace'
9598
import { getTelemetryReasonDesc } from './util/shared'
9699
import { writeSync } from 'fs'
97100
import { format } from 'util'
@@ -400,6 +403,8 @@ export const standalone = (props: RuntimeProps) => {
400403
selectWorkspaceItem: params =>
401404
lspConnection.sendRequest(selectWorkspaceItemRequestType.method, params),
402405
openFileDiff: params => lspConnection.sendNotification(openFileDiffNotificationType.method, params),
406+
openWorkspaceFile: (params: OpenWorkspaceFileParams) =>
407+
lspConnection.sendRequest(openWorkspaceFileRequestType.method, params),
403408
},
404409
window: {
405410
showMessage: params => lspConnection.sendNotification(ShowMessageNotification.method, params),
@@ -409,6 +414,8 @@ export const standalone = (props: RuntimeProps) => {
409414
lspConnection.sendRequest(ShowSaveFileDialogRequestType.method, params),
410415
showOpenDialog: (params: ShowOpenDialogParams) =>
411416
lspConnection.sendRequest(ShowOpenDialogRequestType.method, params),
417+
checkDiagnostics: (params: CheckDiagnosticsParams) =>
418+
lspConnection.sendRequest(CheckDiagnosticsRequestType.method, params),
412419
},
413420
publishDiagnostics: params =>
414421
lspConnection.sendNotification(PublishDiagnosticsNotification.method, params),

runtimes/server-interface/lsp.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ import {
6161
ShowSaveFileDialogResult,
6262
ShowOpenDialogParams,
6363
ShowOpenDialogResult,
64+
CheckDiagnosticsParams,
65+
CheckDiagnosticsResult,
66+
OpenWorkspaceFileParams,
67+
OpenWorkspaceFileResult,
6468
} from '../protocol'
6569

6670
// Re-export whole surface of LSP protocol used in Runtimes.
@@ -154,13 +158,15 @@ export type Lsp = {
154158
handler: RequestHandler<SelectWorkspaceItemParams, SelectWorkspaceItemResult | undefined | null, void>
155159
) => void
156160
openFileDiff: (params: OpenFileDiffParams) => void
161+
openWorkspaceFile: (params: OpenWorkspaceFileParams) => Promise<OpenWorkspaceFileResult>
157162
}
158163
window: {
159164
showMessage: (params: ShowMessageParams) => Promise<void>
160165
showMessageRequest: (params: ShowMessageRequestParams) => Promise<MessageActionItem | null>
161166
showDocument: (params: ShowDocumentParams) => Promise<ShowDocumentResult>
162167
showSaveFileDialog: (params: ShowSaveFileDialogParams) => Promise<ShowSaveFileDialogResult>
163168
showOpenDialog: (params: ShowOpenDialogParams) => Promise<ShowOpenDialogResult>
169+
checkDiagnostics: (params: CheckDiagnosticsParams) => Promise<CheckDiagnosticsResult>
164170
}
165171
extensions: {
166172
onInlineCompletionWithReferences: (

types/window.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { URI } from 'vscode-languageserver-types'
22

33
export const SHOW_SAVE_FILE_DIALOG_REQUEST_METHOD = 'aws/showSaveFileDialog'
44
export const SHOW_OPEN_FILE_DIALOG_REQUEST_METHOD = 'aws/showOpenFileDialog'
5+
export const CHECK_DIAGNOSTICS_REQUEST_METHOD = 'aws/checkDiagnostics'
56
export interface ShowSaveFileDialogParams {
67
// Using untyped string to avoid locking this too strictly.
78
// TODO: Migrate to LanguageKind when it is released in 3.18.0
@@ -27,3 +28,22 @@ export interface ShowOpenDialogParams {
2728
export interface ShowOpenDialogResult {
2829
uris: URI[]
2930
}
31+
32+
export interface DiagnosticInfo {
33+
range: {
34+
start: { line: number; character: number }
35+
end: { line: number; character: number }
36+
}
37+
severity?: number
38+
message: string
39+
source?: string
40+
code?: string | number
41+
}
42+
43+
export interface CheckDiagnosticsParams {
44+
fileDiagnostics: Record<string, DiagnosticInfo[]>
45+
}
46+
47+
export interface CheckDiagnosticsResult {
48+
fileDiagnostics: Record<string, DiagnosticInfo[]>
49+
}

types/workspace.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const DID_WRITE_FILE_NOTIFICATION_METHOD = 'aws/didWriteFile'
88
export const DID_APPEND_FILE_NOTIFICATION_METHOD = 'aws/didAppendFile'
99
export const DID_REMOVE_FILE_OR_DIRECTORY_NOTIFICATION_METHOD = 'aws/didRemoveFileOrDirectory'
1010
export const DID_CREATE_DIRECTORY_NOTIFICATION_METHOD = 'aws/didCreateDirectory'
11+
export const OPEN_WORKSPACE_FILE_REQUEST_METHOD = 'aws/openWorkspaceFile'
1112

1213
export interface SelectWorkspaceItemParams {
1314
canSelectFolders: boolean
@@ -38,3 +39,12 @@ export interface CopyFileParams {
3839
export interface FileParams {
3940
path: string
4041
}
42+
43+
export interface OpenWorkspaceFileParams {
44+
filePath: string
45+
makeActive?: boolean
46+
}
47+
48+
export interface OpenWorkspaceFileResult {
49+
success: boolean
50+
}

0 commit comments

Comments
 (0)