Skip to content

Commit

Permalink
Use posix object in path/posix
Browse files Browse the repository at this point in the history
  • Loading branch information
cooolbros committed Apr 16, 2023
1 parent f6d096b commit ae56434
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
18 changes: 9 additions & 9 deletions extension/lib/server/VDF/VDFLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { VDFDocumentSymbol } from "$lib/VDFDocumentSymbols/VDFDocumentSymbo
import { VDFDocumentSymbols } from "$lib/VDFDocumentSymbols/VDFDocumentSymbols"
import { VDFFormat } from "$lib/VDFFormat/VDFFormat"
import type { VDFFormatStringifyOptions } from "$lib/VDFFormat/VDFFormatStringifyOptions"
import { basename, dirname, relative } from "path/posix"
import { posix } from "path"
import { findBestMatch } from "string-similarity"
import { CodeAction, CodeActionKind, CodeActionParams, CodeLens, CodeLensParams, ColorInformation, ColorPresentation, ColorPresentationParams, Command, CompletionItem, CompletionItemKind, CompletionParams, Connection, Definition, DefinitionParams, Diagnostic, DiagnosticSeverity, DocumentColorParams, DocumentFormattingParams, DocumentLink, DocumentLinkParams, Location, Position, PrepareRenameParams, Range, ReferenceParams, RenameParams, ServerCapabilities, TextDocumentChangeEvent, TextEdit, WorkspaceEdit } from "vscode-languageserver"
import type { TextDocument } from "vscode-languageserver-textdocument"
Expand Down Expand Up @@ -117,10 +117,10 @@ export abstract class VDFLanguageServer extends LanguageServer<VDFDocumentSymbol

if (documentSymbolKey == "#base" && documentSymbol.detail != "") {

const folder = dirname(uri)
const folder = posix.dirname(uri)
const detail = encodeBaseValue(documentSymbol.detail!.toLowerCase())
const baseUri = `${folder}/${detail}`
const newPath = relative(folder, baseUri)
const newPath = posix.relative(folder, baseUri)

if (baseUri == uri) {
diagnostics.push({
Expand Down Expand Up @@ -267,7 +267,7 @@ export abstract class VDFLanguageServer extends LanguageServer<VDFDocumentSymbol
return documentDefinitionReferences
}

const folderUri = dirname(uri)
const folderUri = posix.dirname(uri)
const baseFileUris: string[] = []

// Recursively remove old references
Expand Down Expand Up @@ -375,7 +375,7 @@ export abstract class VDFLanguageServer extends LanguageServer<VDFDocumentSymbol
}

if (this.VDFLanguageServerConfiguration.vpkRootPath) {
const vpkBaseUri = `vpk:///${this.VDFLanguageServerConfiguration.vpkRootPath}/${basename(baseUri)}?vpk=misc`
const vpkBaseUri = `vpk:///${this.VDFLanguageServerConfiguration.vpkRootPath}/${posix.basename(baseUri)}?vpk=misc`
if (await this.fileSystem.exists(vpkBaseUri)) {
return vpkBaseUri
}
Expand Down Expand Up @@ -418,7 +418,7 @@ export abstract class VDFLanguageServer extends LanguageServer<VDFDocumentSymbol
}
}

const baseFolderUri = dirname(baseUri)
const baseFolderUri = posix.dirname(baseUri)

const baseUris = baseDocumentSymbols
.filter((documentSymbol): documentSymbol is VDFDocumentSymbol & { detail: string } => documentSymbol.key == "#base" && documentSymbol.detail != undefined)
Expand Down Expand Up @@ -567,8 +567,8 @@ export abstract class VDFLanguageServer extends LanguageServer<VDFDocumentSymbol
}

const completionItems = filesAutoCompletionKind == "incremental"
? filesCompletion.incremental(this.connection, this.fileSystem, "", dirname(params.textDocument.uri), value, this.VDFLanguageServerConfiguration.completion.extensions, false)
: filesCompletion.all(this.connection, this.fileSystem, "", dirname(params.textDocument.uri), this.VDFLanguageServerConfiguration.completion.extensions, false)
? filesCompletion.incremental(this.connection, this.fileSystem, "", posix.dirname(params.textDocument.uri), value, this.VDFLanguageServerConfiguration.completion.extensions, false)
: filesCompletion.all(this.connection, this.fileSystem, "", posix.dirname(params.textDocument.uri), this.VDFLanguageServerConfiguration.completion.extensions, false)

for (const completionItem of await completionItems) {
set.add(completionItem)
Expand Down Expand Up @@ -761,7 +761,7 @@ export abstract class VDFLanguageServer extends LanguageServer<VDFDocumentSymbol

const fileName = encodeBaseValue(link.data.value.toLowerCase())

const fileUri = `${dirname(link.data.uri)}/${fileName}`
const fileUri = `${posix.dirname(link.data.uri)}/${fileName}`

if (await this.fileSystem.exists(fileUri)) {
documentLink.target = fileUri
Expand Down
14 changes: 7 additions & 7 deletions extension/lib/server/VDF/VGUI/VGUILanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { VDFPosition } from "$lib/VDF/VDFPosition"
import { VDFRange } from "$lib/VDF/VDFRange"
import type { VDFDocumentSymbol } from "$lib/VDFDocumentSymbols/VDFDocumentSymbol"
import type { VDFDocumentSymbols } from "$lib/VDFDocumentSymbols/VDFDocumentSymbols"
import { dirname, extname, normalize, relative } from "path/posix"
import { posix } from "path"
import { CodeActionKind, CodeLens, CodeLensParams, Color, CompletionItem, CompletionItemKind, Connection, Definition, DefinitionParams, Diagnostic, DiagnosticSeverity, DocumentLink, Location, PrepareRenameParams, Range, ReferenceParams, TextDocumentChangeEvent } from "vscode-languageserver"
import type { TextDocument } from "vscode-languageserver-textdocument"
import { z } from "zod"
Expand Down Expand Up @@ -89,13 +89,13 @@ export class VGUILanguageServer extends VDFLanguageServer {
resolve: async (documentLink: DocumentLinkData): Promise<DocumentLink> => {
const hudRoot = this.documentHUDRoots.get(documentLink.data.uri)
if (hudRoot) {
const vmtPath = `${hudRoot}/${normalize(`materials/vgui/${documentLink.data.value}.vmt`)}`
const vmtPath = `${hudRoot}/${posix.normalize(`materials/vgui/${documentLink.data.value}.vmt`)}`
if (await this.fileSystem.exists(vmtPath)) {
documentLink.target = vmtPath
return documentLink
}
}
documentLink.target = `vpk:///${normalize(`materials/vgui/${documentLink.data.value.toLowerCase()}.vmt`)}?vpk=misc`
documentLink.target = `vpk:///${posix.normalize(`materials/vgui/${documentLink.data.value.toLowerCase()}.vmt`)}?vpk=misc`
return documentLink
}
},
Expand Down Expand Up @@ -156,7 +156,7 @@ export class VGUILanguageServer extends VDFLanguageServer {
}
}

const vpkFilePath = `vpk:///${normalize(`${encodeBaseValue(documentLink.data.value.toLowerCase())}`)}?vpk=misc`
const vpkFilePath = `vpk:///${posix.normalize(`${encodeBaseValue(documentLink.data.value.toLowerCase())}`)}?vpk=misc`
if (await this.fileSystem.exists(vpkFilePath)) {
documentLink.target = vpkFilePath
}
Expand Down Expand Up @@ -261,7 +261,7 @@ export class VGUILanguageServer extends VDFLanguageServer {
promises.push(...iterateDirectory(entryUri))
}
}
else if (type == 1 && extname(entry) == ".res") {
else if (type == 1 && posix.extname(entry) == ".res") {
const file = this.fileSystem.readFile(entryUri)
promises.push(file)
file
Expand Down Expand Up @@ -306,7 +306,7 @@ export class VGUILanguageServer extends VDFLanguageServer {
return documentSymbols
})()

const folderUri = dirname(uri)
const folderUri = posix.dirname(uri)
const baseFiles: string[] = []

// Add definition file even if no definitions are declared, since they can be added later e.g. If the entry file has only #base statements
Expand Down Expand Up @@ -492,7 +492,7 @@ export class VGUILanguageServer extends VDFLanguageServer {

const folder = "materials/vgui"
const detail = encodeBaseValue(documentSymbol.detail!.toLowerCase())
const newPath = relative(folder, `${folder}/${detail}`)
const newPath = posix.relative(folder, `${folder}/${detail}`)

if (detail != newPath) {
return {
Expand Down

0 comments on commit ae56434

Please sign in to comment.