Skip to content

Commit 7ea0118

Browse files
committed
chore: import code-format and text-edit types from atom-ide-base
1 parent d43c060 commit 7ea0118

File tree

6 files changed

+27
-57
lines changed

6 files changed

+27
-57
lines changed

lib/adapters/apply-edit-adapter.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as atomIde from 'atom-ide';
1+
import type { TextEdit } from 'atom-ide-base';
22
import Convert from '../convert';
33
import {
44
LanguageClientConnection,
@@ -23,13 +23,13 @@ export default class ApplyEditAdapter {
2323
*/
2424
public static applyEdits(
2525
buffer: TextBuffer,
26-
edits: atomIde.TextEdit[],
26+
edits: TextEdit[],
2727
): number {
2828
const checkpoint = buffer.createCheckpoint();
2929
try {
3030
// Sort edits in reverse order to prevent edit conflicts.
3131
edits.sort((edit1, edit2) => -edit1.oldRange.compare(edit2.oldRange));
32-
edits.reduce((previous: atomIde.TextEdit | null, current) => {
32+
edits.reduce((previous: TextEdit | null, current) => {
3333
ApplyEditAdapter.validateEdit(buffer, current, previous);
3434
buffer.setTextInRange(current.oldRange, current.newText);
3535
return current;
@@ -97,8 +97,8 @@ export default class ApplyEditAdapter {
9797
/** Private: Do some basic sanity checking on the edit ranges. */
9898
private static validateEdit(
9999
buffer: TextBuffer,
100-
edit: atomIde.TextEdit,
101-
prevEdit: atomIde.TextEdit | null,
100+
edit: TextEdit,
101+
prevEdit: TextEdit | null,
102102
): void {
103103
const path = buffer.getPath() || '';
104104
if (prevEdit && edit.oldRange.end.compare(prevEdit.oldRange.start) > 0) {

lib/adapters/code-format-adapter.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as atomIde from 'atom-ide';
1+
import type { TextEdit } from 'atom-ide-base';
22
import Convert from '../convert';
33
import {
44
LanguageClientConnection,
@@ -51,7 +51,7 @@ export default class CodeFormatAdapter {
5151
serverCapabilities: ServerCapabilities,
5252
editor: TextEditor,
5353
range: Range,
54-
): Promise<atomIde.TextEdit[]> {
54+
): Promise<TextEdit[]> {
5555
if (serverCapabilities.documentRangeFormattingProvider) {
5656
return CodeFormatAdapter.formatRange(connection, editor, range);
5757
}
@@ -74,7 +74,7 @@ export default class CodeFormatAdapter {
7474
public static async formatDocument(
7575
connection: LanguageClientConnection,
7676
editor: TextEditor,
77-
): Promise<atomIde.TextEdit[]> {
77+
): Promise<TextEdit[]> {
7878
const edits = await connection.documentFormatting(CodeFormatAdapter.createDocumentFormattingParams(editor));
7979
return Convert.convertLsTextEdits(edits);
8080
}
@@ -107,7 +107,7 @@ export default class CodeFormatAdapter {
107107
connection: LanguageClientConnection,
108108
editor: TextEditor,
109109
range: Range,
110-
): Promise<atomIde.TextEdit[]> {
110+
): Promise<TextEdit[]> {
111111
const edits = await connection.documentRangeFormatting(
112112
CodeFormatAdapter.createDocumentRangeFormattingParams(editor, range),
113113
);
@@ -150,7 +150,7 @@ export default class CodeFormatAdapter {
150150
editor: TextEditor,
151151
point: Point,
152152
character: string,
153-
): Promise<atomIde.TextEdit[]> {
153+
): Promise<TextEdit[]> {
154154
const edits = await connection.documentOnTypeFormatting(
155155
CodeFormatAdapter.createDocumentOnTypeFormattingParams(editor, point, character),
156156
);

lib/adapters/rename-adapter.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as atomIde from 'atom-ide';
2+
import type { TextEdit as AtomTextEdit } from 'atom-ide-base';
23
import Convert from '../convert';
34
import {
45
Point,
@@ -22,7 +23,7 @@ export default class RenameAdapter {
2223
editor: TextEditor,
2324
point: Point,
2425
newName: string,
25-
): Promise<Map<atomIde.IdeUri, atomIde.TextEdit[]> | null> {
26+
): Promise<Map<atomIde.IdeUri, AtomTextEdit[]> | null> {
2627
const edit = await connection.rename(
2728
RenameAdapter.createRenameParams(editor, point, newName),
2829
);
@@ -49,7 +50,7 @@ export default class RenameAdapter {
4950

5051
public static convertChanges(
5152
changes: { [uri: string]: TextEdit[] },
52-
): Map<atomIde.IdeUri, atomIde.TextEdit[]> {
53+
): Map<atomIde.IdeUri, AtomTextEdit[]> {
5354
const result = new Map();
5455
Object.keys(changes).forEach((uri) => {
5556
result.set(
@@ -62,7 +63,7 @@ export default class RenameAdapter {
6263

6364
public static convertDocumentChanges(
6465
documentChanges: TextDocumentEdit[],
65-
): Map<atomIde.IdeUri, atomIde.TextEdit[]> {
66+
): Map<atomIde.IdeUri, AtomTextEdit[]> {
6667
const result = new Map();
6768
documentChanges.forEach((documentEdit) => {
6869
result.set(

lib/auto-languageclient.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as ls from './languageclient';
33
import * as rpc from 'vscode-jsonrpc';
44
import * as path from 'path';
55
import * as atomIde from 'atom-ide';
6-
import type { OutlineProvider, Outline, DefinitionProvider, DefinitionQueryResult, FindReferencesProvider, FindReferencesReturn, Datatip, DatatipService } from 'atom-ide-base';
6+
import type { OutlineProvider, Outline, DefinitionProvider, DefinitionQueryResult, FindReferencesProvider, FindReferencesReturn, Datatip, DatatipService, TextEdit, RangeCodeFormatProvider, FileCodeFormatProvider, OnSaveCodeFormatProvider, OnTypeCodeFormatProvider } from 'atom-ide-base';
77
import * as linter from 'atom/linter';
88
import Convert from './convert.js';
99
import ApplyEditAdapter from './adapters/apply-edit-adapter';
@@ -42,7 +42,7 @@ import {
4242
TextEditor,
4343
} from 'atom';
4444
import * as ac from 'atom/autocomplete-plus';
45-
import { TextEdit, CodeAction } from 'atom-ide';
45+
import { CodeAction } from 'atom-ide';
4646

4747
export { ActiveServer, LanguageClientConnection, LanguageServerProcess };
4848
export type ConnectionType = 'stdio' | 'socket' | 'ipc';
@@ -634,15 +634,15 @@ export default class AutoLanguageClient {
634634
}
635635

636636
// Code Format via LS formatDocument & formatDocumentRange------------
637-
public provideCodeFormat(): atomIde.RangeCodeFormatProvider {
637+
public provideCodeFormat(): RangeCodeFormatProvider {
638638
return {
639639
grammarScopes: this.getGrammarScopes(),
640640
priority: 1,
641641
formatCode: this.getCodeFormat.bind(this),
642642
};
643643
}
644644

645-
protected async getCodeFormat(editor: TextEditor, range: Range): Promise<atomIde.TextEdit[]> {
645+
protected async getCodeFormat(editor: TextEditor, range: Range): Promise<TextEdit[]> {
646646
const server = await this._serverManager.getServer(editor);
647647
if (server == null || !CodeFormatAdapter.canAdapt(server.capabilities)) {
648648
return [];
@@ -651,15 +651,15 @@ export default class AutoLanguageClient {
651651
return CodeFormatAdapter.format(server.connection, server.capabilities, editor, range);
652652
}
653653

654-
public provideRangeCodeFormat(): atomIde.RangeCodeFormatProvider {
654+
public provideRangeCodeFormat(): RangeCodeFormatProvider {
655655
return {
656656
grammarScopes: this.getGrammarScopes(),
657657
priority: 1,
658658
formatCode: this.getRangeCodeFormat.bind(this),
659659
};
660660
}
661661

662-
protected async getRangeCodeFormat(editor: TextEditor, range: Range): Promise<atomIde.TextEdit[]> {
662+
protected async getRangeCodeFormat(editor: TextEditor, range: Range): Promise<TextEdit[]> {
663663
const server = await this._serverManager.getServer(editor);
664664
if (server == null || !server.capabilities.documentRangeFormattingProvider) {
665665
return [];
@@ -668,23 +668,23 @@ export default class AutoLanguageClient {
668668
return CodeFormatAdapter.formatRange(server.connection, editor, range);
669669
}
670670

671-
public provideFileCodeFormat(): atomIde.FileCodeFormatProvider {
671+
public provideFileCodeFormat(): FileCodeFormatProvider {
672672
return {
673673
grammarScopes: this.getGrammarScopes(),
674674
priority: 1,
675675
formatEntireFile: this.getFileCodeFormat.bind(this),
676676
};
677677
}
678678

679-
public provideOnSaveCodeFormat(): atomIde.OnSaveCodeFormatProvider {
679+
public provideOnSaveCodeFormat(): OnSaveCodeFormatProvider {
680680
return {
681681
grammarScopes: this.getGrammarScopes(),
682682
priority: 1,
683683
formatOnSave: this.getFileCodeFormat.bind(this),
684684
};
685685
}
686686

687-
protected async getFileCodeFormat(editor: TextEditor): Promise<atomIde.TextEdit[]> {
687+
protected async getFileCodeFormat(editor: TextEditor): Promise<TextEdit[]> {
688688
const server = await this._serverManager.getServer(editor);
689689
if (server == null || !server.capabilities.documentFormattingProvider) {
690690
return [];
@@ -693,7 +693,7 @@ export default class AutoLanguageClient {
693693
return CodeFormatAdapter.formatDocument(server.connection, editor);
694694
}
695695

696-
public provideOnTypeCodeFormat(): atomIde.OnTypeCodeFormatProvider {
696+
public provideOnTypeCodeFormat(): OnTypeCodeFormatProvider {
697697
return {
698698
grammarScopes: this.getGrammarScopes(),
699699
priority: 1,
@@ -705,7 +705,7 @@ export default class AutoLanguageClient {
705705
editor: TextEditor,
706706
point: Point,
707707
character: string,
708-
): Promise<atomIde.TextEdit[]> {
708+
): Promise<TextEdit[]> {
709709
const server = await this._serverManager.getServer(editor);
710710
if (server == null || !server.capabilities.documentOnTypeFormattingProvider) {
711711
return [];

lib/convert.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
import { TextEdit } from 'atom-ide-base';
22
import * as ls from './languageclient';
33
import * as URL from 'url';
44
import {
@@ -10,7 +10,6 @@ import {
1010
import {
1111
Diagnostic,
1212
DiagnosticType,
13-
TextEdit,
1413
} from 'atom-ide';
1514

1615
/**

typings/atom-ide/index.d.ts

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,10 @@
11
declare module 'atom-ide' {
22
import { Disposable, Point, Range, TextEditor } from 'atom';
33
import * as ac from 'atom/autocomplete-plus';
4+
import { TextEdit } from 'atom-ide-base';
45

56
export type IdeUri = string;
67

7-
export interface FileCodeFormatProvider {
8-
formatEntireFile: (editor: TextEditor, range: Range) => Promise<TextEdit[]>;
9-
priority: number;
10-
grammarScopes: string[];
11-
}
12-
13-
export interface RangeCodeFormatProvider {
14-
formatCode: (editor: TextEditor, range: Range) => Promise<TextEdit[]>;
15-
priority: number;
16-
grammarScopes: string[];
17-
}
18-
19-
export interface OnSaveCodeFormatProvider {
20-
formatOnSave: (editor: TextEditor) => Promise<TextEdit[]>;
21-
priority: number;
22-
grammarScopes: string[];
23-
}
24-
25-
export interface OnTypeCodeFormatProvider {
26-
formatAtPosition: (editor: TextEditor, position: Point, character: string) => Promise<TextEdit[]>;
27-
priority: number;
28-
grammarScopes: string[];
29-
}
30-
31-
export interface TextEdit {
32-
oldRange: Range;
33-
newText: string;
34-
/** If included, this will be used to verify that the edit still applies cleanly. */
35-
oldText?: string;
36-
}
37-
388
export interface CodeHighlightProvider {
399
highlight(editor: TextEditor, bufferPosition: Point): Promise<Range[] | null>;
4010
priority: number;

0 commit comments

Comments
 (0)