Skip to content

Commit

Permalink
rename files associated with lsp
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Jan 31, 2023
1 parent 43493b0 commit be99a1c
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 165 deletions.
4 changes: 2 additions & 2 deletions extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { Setup } from './setup'
import { definedAndNonEmpty } from './util/array'
import { stopProcesses } from './processExecution'
import { Flag } from './cli/dvc/constants'
import { LanguageClientWrapper } from './lspClient/languageClient'
import { LanguageClient } from './languageClient'

export class Extension extends Disposable {
protected readonly internalCommands: InternalCommands
Expand Down Expand Up @@ -257,7 +257,7 @@ export class Extension extends Disposable {
void showWalkthroughOnFirstUse(env.isNewAppInstall)
this.dispose.track(recommendRedHatExtensionOnce())

this.dispose.track(new LanguageClientWrapper())
this.dispose.track(new LanguageClient())
}

public async initialize() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { workspace } from 'vscode'
import {
LanguageClient,
LanguageClient as Client,
LanguageClientOptions,
ServerOptions,
TransportKind
Expand All @@ -9,8 +9,8 @@ import { documentSelector, serverModule } from 'dvc-vscode-lsp'
import { Disposable } from '../class/dispose'
import { readFileContents } from '../fileSystem'

export class LanguageClientWrapper extends Disposable {
private client: LanguageClient
export class LanguageClient extends Disposable {
private client: Client

constructor() {
super()
Expand All @@ -24,7 +24,7 @@ export class LanguageClientWrapper extends Disposable {
}

this.client = this.dispose.track(
new LanguageClient(
new Client(
'dvc-vscode-lsp',
'DVC Language Server',
this.getServerOptions(),
Expand Down
43 changes: 13 additions & 30 deletions languageServer/src/LanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import {
} from 'vscode-languageserver/node'
import { TextDocument } from 'vscode-languageserver-textdocument'
import { URI } from 'vscode-uri'
import { TextDocumentWrapper } from './TextDocumentWrapper'
import {
getTextDocumentLocation,
getUriLocation,
symbolAt
} from './textDocument'

export class LanguageServer {
private documentsKnownToEditor!: TextDocuments<TextDocument>
Expand All @@ -37,25 +41,9 @@ export class LanguageServer {
connection.listen()
}

private getAllDocuments() {
const openDocuments = this.documentsKnownToEditor.all()
return openDocuments.map(doc => this.wrap(doc))
}

private getDocument(params: TextDocumentPositionParams | CodeActionParams) {
const uri = params.textDocument.uri

const doc = this.documentsKnownToEditor.get(uri)

if (!doc) {
return null
}

return this.wrap(doc)
}

private wrap(doc: TextDocument) {
return new TextDocumentWrapper(doc)
return this.documentsKnownToEditor.get(uri)
}

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

const filePath = symbolUnderCursor.name

const matchingFiles = this.getAllDocuments().filter(doc =>
URI.parse(doc.uri).fsPath.endsWith(filePath)
)
const matchingFiles = this.documentsKnownToEditor
.all()
.filter(doc => URI.parse(doc.uri).fsPath.endsWith(filePath))

return matchingFiles.map(doc => doc.getLocation())
return matchingFiles.map(doc => getTextDocumentLocation(doc))
}

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

const symbolUnderCursor = document?.symbolAt(params.position)
const symbolUnderCursor = symbolAt(document, params.position)

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

private async checkIfSymbolsAreFiles(
connection: _Connection,
document: TextDocumentWrapper,
document: TextDocument,
symbolUnderCursor: DocumentSymbol,
fileLocations: Location[]
) {
Expand All @@ -113,17 +101,12 @@ export class LanguageServer {
contents: string
} | null>('readFileContents', possiblePath)
if (file) {
const location = this.getLocation(possiblePath, file.contents)
const location = getUriLocation(possiblePath, file.contents)
fileLocations.push(location)
}
}
}

private getLocation(path: string, contents: string) {
const doc = this.wrap(TextDocument.create(path, 'plain/text', 0, contents))
return doc.getLocation()
}

private arrayOrSingleResponse<T>(elements: T[]) {
if (elements.length === 1) {
return elements[0]
Expand Down
127 changes: 0 additions & 127 deletions languageServer/src/TextDocumentWrapper.ts

This file was deleted.

2 changes: 1 addition & 1 deletion languageServer/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createConnection, ProposedFeatures } from 'vscode-languageserver/node'
import { LanguageServer } from './LanguageServer'
import { LanguageServer } from './languageServer'

const dvcLanguageServer = new LanguageServer()

Expand Down
2 changes: 1 addition & 1 deletion languageServer/src/test/utils/setup-test-connections.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Duplex } from 'stream'
import { Connection, createConnection } from 'vscode-languageserver/node'
import { LanguageServer } from '../../LanguageServer'
import { LanguageServer } from '../../languageServer'

class TestStream extends Duplex {
_write(chunk: string, _encoding: string, done: () => void) {
Expand Down
Loading

0 comments on commit be99a1c

Please sign in to comment.