parent
e3eae62e37
commit
0f3e462afd
2 changed files with 13 additions and 5 deletions
|
@ -3,7 +3,7 @@
|
||||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
import cp from 'child_process'
|
import cp from 'child_process'
|
||||||
import { ServiceStat, Uri, window, workspace } from 'coc.nvim'
|
import { Document, ServiceStat, Uri, window, workspace } from 'coc.nvim'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import os from 'os'
|
import os from 'os'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
@ -491,7 +491,7 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
|
||||||
|
|
||||||
public toResource(filepath: string): string {
|
public toResource(filepath: string): string {
|
||||||
if (this._apiVersion.gte(API.v213)) {
|
if (this._apiVersion.gte(API.v213)) {
|
||||||
if (filepath.startsWith('untitled:')) {
|
if (filepath.startsWith(this.inMemoryResourcePrefix + 'untitled:')) {
|
||||||
let resource = Uri.parse(filepath)
|
let resource = Uri.parse(filepath)
|
||||||
if (this.inMemoryResourcePrefix) {
|
if (this.inMemoryResourcePrefix) {
|
||||||
const dirName = path.dirname(resource.path)
|
const dirName = path.dirname(resource.path)
|
||||||
|
@ -524,14 +524,22 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getDocument(resource: string): Document | undefined {
|
||||||
|
if (resource.startsWith('untitled:')) {
|
||||||
|
let bufnr = parseInt(resource.split(':', 2)[1], 10)
|
||||||
|
return workspace.getDocument(bufnr)
|
||||||
|
}
|
||||||
|
return workspace.getDocument(resource)
|
||||||
|
}
|
||||||
|
|
||||||
private get inMemoryResourcePrefix(): string {
|
private get inMemoryResourcePrefix(): string {
|
||||||
return this._apiVersion.gte(API.v270) ? '^' : ''
|
return this._apiVersion.gte(API.v270) ? '^' : ''
|
||||||
}
|
}
|
||||||
|
|
||||||
public asUrl(filepath: string): Uri {
|
public asUrl(filepath: string): Uri {
|
||||||
if (this._apiVersion.gte(API.v213)) {
|
if (this._apiVersion.gte(API.v213)) {
|
||||||
if (filepath.startsWith('untitled:')) {
|
if (filepath.startsWith(this.inMemoryResourcePrefix + 'untitled:')) {
|
||||||
let resource = Uri.parse(filepath)
|
let resource = Uri.parse(filepath.slice(this.inMemoryResourcePrefix.length))
|
||||||
if (this.inMemoryResourcePrefix) {
|
if (this.inMemoryResourcePrefix) {
|
||||||
const dirName = path.dirname(resource.path)
|
const dirName = path.dirname(resource.path)
|
||||||
const fileName = path.basename(resource.path)
|
const fileName = path.basename(resource.path)
|
||||||
|
|
|
@ -181,7 +181,7 @@ export default class TypeScriptServiceClientHost implements Disposable {
|
||||||
|
|
||||||
public async findLanguage(uri: string): Promise<LanguageProvider> {
|
public async findLanguage(uri: string): Promise<LanguageProvider> {
|
||||||
try {
|
try {
|
||||||
let doc = await workspace.loadFile(uri)
|
let doc = this.client.getDocument(uri)
|
||||||
if (!doc) return undefined
|
if (!doc) return undefined
|
||||||
let languages = Array.from(this.languagePerId.values())
|
let languages = Array.from(this.languagePerId.values())
|
||||||
return languages.find(language => language.handles(uri, doc.textDocument))
|
return languages.find(language => language.handles(uri, doc.textDocument))
|
||||||
|
|
Loading…
Add table
Reference in a new issue