-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[webview] fix #5786: unify the icon path resolution
Also: - preserve the icon path between user sessions and reconnections - add missing icon-path getter api Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
- Loading branch information
Showing
9 changed files
with
122 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2019 Red Hat, Inc. and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import * as path from 'path'; | ||
import Uri from 'vscode-uri'; | ||
import { IconUrl, PluginPackage } from '../common/plugin-protocol'; | ||
import { Plugin } from '../common/plugin-api-rpc'; | ||
|
||
export type PluginIconPath = string | Uri | { | ||
light: string | Uri, | ||
dark: string | Uri | ||
}; | ||
export namespace PluginIconPath { | ||
export function toUrl(iconPath: PluginIconPath | undefined, plugin: Plugin): IconUrl | undefined { | ||
if (!iconPath) { | ||
return undefined; | ||
} | ||
if (typeof iconPath === 'object' && 'light' in iconPath) { | ||
return { | ||
light: asString(iconPath.light, plugin), | ||
dark: asString(iconPath.dark, plugin) | ||
}; | ||
} | ||
return asString(iconPath, plugin); | ||
} | ||
export function asString(arg: string | Uri, plugin: Plugin): string { | ||
arg = arg instanceof Uri && arg.scheme === 'file' ? arg.fsPath : arg; | ||
if (typeof arg !== 'string') { | ||
return arg.toString(true); | ||
} | ||
const { packagePath } = plugin.rawModel; | ||
const absolutePath = path.isAbsolute(arg) ? arg : path.join(packagePath, arg); | ||
const normalizedPath = path.normalize(absolutePath); | ||
const relativePath = path.relative(packagePath, normalizedPath); | ||
return PluginPackage.toPluginUrl(plugin.rawModel, relativePath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.