Skip to content

Commit ea27142

Browse files
authored
Rename files associated with LSP (#3185)
1 parent f145f00 commit ea27142

File tree

7 files changed

+157
-167
lines changed

7 files changed

+157
-167
lines changed

extension/src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import { Setup } from './setup'
5050
import { definedAndNonEmpty } from './util/array'
5151
import { stopProcesses } from './processExecution'
5252
import { Flag } from './cli/dvc/constants'
53-
import { LanguageClientWrapper } from './lspClient/languageClient'
53+
import { LanguageClient } from './languageClient'
5454

5555
export class Extension extends Disposable {
5656
protected readonly internalCommands: InternalCommands
@@ -257,7 +257,7 @@ export class Extension extends Disposable {
257257
void showWalkthroughOnFirstUse(env.isNewAppInstall)
258258
this.dispose.track(recommendRedHatExtensionOnce())
259259

260-
this.dispose.track(new LanguageClientWrapper())
260+
this.dispose.track(new LanguageClient())
261261
}
262262

263263
public async initialize() {

extension/src/lspClient/languageClient.ts renamed to extension/src/languageClient/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { workspace } from 'vscode'
22
import {
3-
LanguageClient,
3+
LanguageClient as Client,
44
LanguageClientOptions,
55
ServerOptions,
66
TransportKind
@@ -9,8 +9,8 @@ import { documentSelector, serverModule } from 'dvc-vscode-lsp'
99
import { Disposable } from '../class/dispose'
1010
import { readFileContents } from '../fileSystem'
1111

12-
export class LanguageClientWrapper extends Disposable {
13-
private client: LanguageClient
12+
export class LanguageClient extends Disposable {
13+
private client: Client
1414

1515
constructor() {
1616
super()
@@ -24,7 +24,7 @@ export class LanguageClientWrapper extends Disposable {
2424
}
2525

2626
this.client = this.dispose.track(
27-
new LanguageClient(
27+
new Client(
2828
'dvc-vscode-lsp',
2929
'DVC Language Server',
3030
this.getServerOptions(),

languageServer/src/TextDocumentWrapper.ts

Lines changed: 0 additions & 127 deletions
This file was deleted.

languageServer/src/LanguageServer.ts renamed to languageServer/src/languageServer.ts

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ import {
1414
} from 'vscode-languageserver/node'
1515
import { TextDocument } from 'vscode-languageserver-textdocument'
1616
import { URI } from 'vscode-uri'
17-
import { TextDocumentWrapper } from './TextDocumentWrapper'
17+
import {
18+
getTextDocumentLocation,
19+
getUriLocation,
20+
symbolAt
21+
} from './textDocument'
1822

1923
export class LanguageServer {
2024
private documentsKnownToEditor!: TextDocuments<TextDocument>
@@ -37,25 +41,9 @@ export class LanguageServer {
3741
connection.listen()
3842
}
3943

40-
private getAllDocuments() {
41-
const openDocuments = this.documentsKnownToEditor.all()
42-
return openDocuments.map(doc => this.wrap(doc))
43-
}
44-
4544
private getDocument(params: TextDocumentPositionParams | CodeActionParams) {
4645
const uri = params.textDocument.uri
47-
48-
const doc = this.documentsKnownToEditor.get(uri)
49-
50-
if (!doc) {
51-
return null
52-
}
53-
54-
return this.wrap(doc)
55-
}
56-
57-
private wrap(doc: TextDocument) {
58-
return new TextDocumentWrapper(doc)
46+
return this.documentsKnownToEditor.get(uri)
5947
}
6048

6149
private getKnownDocumentLocations(symbolUnderCursor: DocumentSymbol) {
@@ -65,17 +53,17 @@ export class LanguageServer {
6553

6654
const filePath = symbolUnderCursor.name
6755

68-
const matchingFiles = this.getAllDocuments().filter(doc =>
69-
URI.parse(doc.uri).fsPath.endsWith(filePath)
70-
)
56+
const matchingFiles = this.documentsKnownToEditor
57+
.all()
58+
.filter(doc => URI.parse(doc.uri).fsPath.endsWith(filePath))
7159

72-
return matchingFiles.map(doc => doc.getLocation())
60+
return matchingFiles.map(doc => getTextDocumentLocation(doc))
7361
}
7462

7563
private async onDefinition(params: DefinitionParams, connection: Connection) {
7664
const document = this.getDocument(params)
7765

78-
const symbolUnderCursor = document?.symbolAt(params.position)
66+
const symbolUnderCursor = symbolAt(document, params.position)
7967

8068
if (!(document && symbolUnderCursor)) {
8169
return null
@@ -101,7 +89,7 @@ export class LanguageServer {
10189

10290
private async checkIfSymbolsAreFiles(
10391
connection: _Connection,
104-
document: TextDocumentWrapper,
92+
document: TextDocument,
10593
symbolUnderCursor: DocumentSymbol,
10694
fileLocations: Location[]
10795
) {
@@ -113,17 +101,12 @@ export class LanguageServer {
113101
contents: string
114102
} | null>('readFileContents', possiblePath)
115103
if (file) {
116-
const location = this.getLocation(possiblePath, file.contents)
104+
const location = getUriLocation(possiblePath, file.contents)
117105
fileLocations.push(location)
118106
}
119107
}
120108
}
121109

122-
private getLocation(path: string, contents: string) {
123-
const doc = this.wrap(TextDocument.create(path, 'plain/text', 0, contents))
124-
return doc.getLocation()
125-
}
126-
127110
private arrayOrSingleResponse<T>(elements: T[]) {
128111
if (elements.length === 1) {
129112
return elements[0]

languageServer/src/server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { createConnection, ProposedFeatures } from 'vscode-languageserver/node'
2-
import { LanguageServer } from './LanguageServer'
2+
import { LanguageServer } from './languageServer'
33

4-
const dvcLanguageServer = new LanguageServer()
4+
const languageServer = new LanguageServer()
55

66
const connection = createConnection(ProposedFeatures.all)
77

8-
dvcLanguageServer.listen(connection)
8+
languageServer.listen(connection)

languageServer/src/test/utils/setup-test-connections.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Duplex } from 'stream'
22
import { Connection, createConnection } from 'vscode-languageserver/node'
3-
import { LanguageServer } from '../../LanguageServer'
3+
import { LanguageServer } from '../../languageServer'
44

55
class TestStream extends Duplex {
66
_write(chunk: string, _encoding: string, done: () => void) {

0 commit comments

Comments
 (0)