Skip to content

Commit

Permalink
poc file rename participation
Browse files Browse the repository at this point in the history
  • Loading branch information
atscott committed May 18, 2021
1 parent 458efc8 commit da306f9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
38 changes: 37 additions & 1 deletion client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as lsp from 'vscode-languageclient/node';

import {ProjectLoadingFinish, ProjectLoadingStart, SuggestStrictMode, SuggestStrictModeParams} from '../common/notifications';
import {NgccProgress, NgccProgressToken, NgccProgressType} from '../common/progress';
import {GetComponentsWithTemplateFile, GetTcbRequest, IsInAngularProject} from '../common/requests';
import {GetComponentsWithTemplateFile, GetEditsForFileRenameParams, GetEditsForFileRenameRequest, GetTcbRequest, IsInAngularProject} from '../common/requests';
import {resolve, Version} from '../common/resolver';

import {isInsideComponentDecorator, isInsideInlineTemplateRegion, isInsideStringLiteral} from './embedded_support';
Expand Down Expand Up @@ -147,6 +147,42 @@ export class AngularLanguageClient implements vscode.Disposable {
}
}
};
vscode.workspace.onWillRenameFiles((e: vscode.FileWillRenameEvent) => {
if (!this.client) {
return;
}

const c2pConverter = this.client.code2ProtocolConverter;
const requests: Array<Promise<lsp.WorkspaceEdit|null>> = [];
for (let f of e.files) {
requests.push(this.client.sendRequest(GetEditsForFileRenameRequest, {
oldUri: c2pConverter.asUri(f.oldUri),
newUri: c2pConverter.asUri(f.newUri),
}));
}
const response = Promise.all(requests).then(allEdits => {
const final: lsp.WorkspaceEdit = {};
for (const edit of allEdits) {
if (!edit) {
continue;
}
final.changes = {...final.changes, ...edit.changes};
if (edit.documentChanges && edit.documentChanges.length > 0) {
if (!final.documentChanges) {
final.documentChanges = [];
}
final.documentChanges.push(...edit.documentChanges);
}
final.changeAnnotations = {...final.changeAnnotations, ...edit.changeAnnotations};
}
if (!final.changeAnnotations && !final.changes && !final.documentChanges) {
return undefined;
}
const p2cConverter = this.client!.protocol2CodeConverter;
return p2cConverter.asWorkspaceEdit(final);
})
e.waitUntil(response);
});
}

private async isInAngularProject(doc: vscode.TextDocument): Promise<boolean> {
Expand Down
9 changes: 9 additions & 0 deletions common/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,21 @@ export const GetComponentsWithTemplateFile = new lsp.RequestType<
export interface GetComponentsWithTemplateFileParams {
textDocument: lsp.TextDocumentIdentifier;
}
export interface GetEditsForFileRenameParams {
oldUri: lsp.URI;
newUri: lsp.URI;
}

export const GetEditsForFileRenameRequest =
new lsp.RequestType<GetEditsForFileRenameParams, lsp.WorkspaceEdit|null, /* error */ void>(
'angular/getEditsForFileRename');

export interface GetTcbParams {
textDocument: lsp.TextDocumentIdentifier;
position: lsp.Position;
}


export const GetTcbRequest =
new lsp.RequestType<GetTcbParams, GetTcbResponse|null, /* error */ void>('angular/getTcb');

Expand Down
7 changes: 6 additions & 1 deletion server/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import * as lsp from 'vscode-languageserver/node';
import {ServerOptions} from '../common/initialize';
import {ProjectLanguageService, ProjectLoadingFinish, ProjectLoadingStart, SuggestStrictMode} from '../common/notifications';
import {NgccProgressToken, NgccProgressType} from '../common/progress';
import {GetComponentsWithTemplateFile, GetTcbParams, GetTcbRequest, GetTcbResponse, IsInAngularProject, IsInAngularProjectParams} from '../common/requests';
import {GetComponentsWithTemplateFile, GetEditsForFileRenameParams, GetEditsForFileRenameRequest, GetTcbParams, GetTcbRequest, GetTcbResponse, IsInAngularProject, IsInAngularProjectParams} from '../common/requests';

import {readNgCompletionData, tsCompletionEntryToLspCompletionItem} from './completion';
import {tsDiagnosticToLspDiagnostic} from './diagnostic';
Expand Down Expand Up @@ -170,11 +170,16 @@ export class Session {
conn.onRequest(GetComponentsWithTemplateFile, p => this.onGetComponentsWithTemplateFile(p));
conn.onRequest(GetTcbRequest, p => this.onGetTcb(p));
conn.onRequest(IsInAngularProject, p => this.isInAngularProject(p));
conn.onRequest(GetEditsForFileRenameRequest, p => this.getEditsForFileRename(p));
conn.onCodeLens(p => this.onCodeLens(p));
conn.onCodeLensResolve(p => this.onCodeLensResolve(p));
conn.onSignatureHelp(p => this.onSignatureHelp(p));
}

private getEditsForFileRename(p: GetEditsForFileRenameParams): lsp.WorkspaceEdit|null {
return null;
}

private isInAngularProject(params: IsInAngularProjectParams): boolean {
const filePath = uriToFilePath(params.textDocument.uri);
if (!filePath) {
Expand Down

0 comments on commit da306f9

Please sign in to comment.