Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,8 @@
"sinon": "^20.0.0",
"ts-mockito": "^2.6.1",
"ts-node": "^10.9.2",
"typescript": "^5.8.3"
"typescript": "^5.8.3",
"vscode-uri": "^3.1.0"
},
"dependencies": {
"@vscode/debugadapter": "^1.68.0",
Expand Down
18 changes: 9 additions & 9 deletions vscode/src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
import { workspace, commands, Uri, window } from "vscode";
import { workspace, commands, window } from "vscode";
import { LanguageClient } from "vscode-languageclient/node";
import { nbCommands, builtInCommands, extCommands } from "./commands";
import { l10n } from "../localiser";
import * as os from 'os';
import * as fs from 'fs';
import { ICommand } from "./types";
import { getContextUri, isNbCommandRegistered } from "./utils";
import { isString } from "../utils";
import { getContextUriFromFile, isNbCommandRegistered } from "./utils";
import { FileUtils, isString } from "../utils";
import { globalState } from "../globalState";

const newFromTemplate = async (ctx: any, template: any) => {
Expand All @@ -40,7 +40,7 @@ const newFromTemplate = async (ctx: any, template: any) => {
if (!fs.existsSync(folderPath)) {
await fs.promises.mkdir(folderPath);
}
const folderPathUri = Uri.file(folderPath);
const folderPathUri = FileUtils.toUri(folderPath);
await commands.executeCommand(nbCommands.newFromTemplate, folderPathUri.toString());
await commands.executeCommand(builtInCommands.openFolder, folderPathUri);

Expand All @@ -52,16 +52,16 @@ const newFromTemplate = async (ctx: any, template: any) => {
if (isString(template)) {
params.push(template);
}
params.push(getContextUri(ctx)?.toString(), window.activeTextEditor?.document?.uri?.toString());
params.push(getContextUriFromFile(ctx)?.toString(), window.activeTextEditor?.document?.uri?.toString());
const res = await commands.executeCommand(nbCommands.newFromTemplate, ...params);

if (isString(res)) {
let newFile = Uri.parse(res as string);
let newFile = FileUtils.toUri(res as string, true);
await window.showTextDocument(newFile, { preview: false });
} else if (Array.isArray(res)) {
for (let r of res) {
if (isString(r)) {
let newFile = Uri.parse(r as string);
let newFile = FileUtils.toUri(r as string, true);
await window.showTextDocument(newFile, { preview: false });
}
}
Expand All @@ -74,9 +74,9 @@ const newFromTemplate = async (ctx: any, template: any) => {
const newProject = async (ctx: any) => {
const client: LanguageClient = await globalState.getClientPromise().client;
if (await isNbCommandRegistered(nbCommands.newProject)) {
const res = await commands.executeCommand(nbCommands.newProject, getContextUri(ctx)?.toString());
const res = await commands.executeCommand(nbCommands.newProject, getContextUriFromFile(ctx)?.toString());
if (isString(res)) {
let newProject = Uri.parse(res as string);
let newProject = FileUtils.toUri(res as string, true);

const OPEN_IN_NEW_WINDOW = l10n.value("jdk.extension.label.openInNewWindow");
const ADD_TO_CURRENT_WORKSPACE = l10n.value("jdk.extension.label.addToWorkSpace");
Expand Down
14 changes: 7 additions & 7 deletions vscode/src/commands/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/

import * as vscode from 'vscode';
import { builtInCommands, extCommands } from "./commands";
import { extCommands } from "./commands";
import { ICommand } from "./types";
import { extConstants } from '../constants';
import { getContextUri } from './utils';
import { getContextUriFromFile } from './utils';

const runTest = async (uri: any, methodName? : string, launchConfiguration?: string) => {
await runDebug(true, true, uri, methodName, launchConfiguration);
Expand All @@ -33,23 +33,23 @@ const debugSingle = async (uri: any, methodName? : string, launchConfiguration?:
await runDebug(false, false, uri, methodName, launchConfiguration);
}
const projectRun = async (node: any, launchConfiguration? : string) => {
return runDebug(true, false, getContextUri(node)?.toString() || '', undefined, launchConfiguration, true);
return runDebug(true, false, getContextUriFromFile(node)?.toString() || '', undefined, launchConfiguration, true);
}
const projectDebug = async (node: any, launchConfiguration? : string) => {
return runDebug(false, false, getContextUri(node)?.toString() || '', undefined, launchConfiguration, true);
return runDebug(false, false, getContextUriFromFile(node)?.toString() || '', undefined, launchConfiguration, true);
}
const projectTest = async (node: any, launchConfiguration? : string) => {
return runDebug(true, true, getContextUri(node)?.toString() || '', undefined, launchConfiguration, true);
return runDebug(true, true, getContextUriFromFile(node)?.toString() || '', undefined, launchConfiguration, true);
}
const projectTestDebug = async (node: any, launchConfiguration? : string) => {
return runDebug(false, true, getContextUri(node)?.toString() || '', undefined, launchConfiguration, true);
return runDebug(false, true, getContextUriFromFile(node)?.toString() || '', undefined, launchConfiguration, true);
}
const packageTest = async (uri: any, launchConfiguration? : string) => {
await runDebug(true, true, uri, undefined, launchConfiguration);
}

const runDebug = async (noDebug: boolean, testRun: boolean, uri: any, methodName?: string, launchConfiguration?: string, project : boolean = false, ) => {
const docUri = getContextUri(uri);
const docUri = getContextUriFromFile(uri);
if (docUri) {
let debugConfig : vscode.DebugConfiguration = {
type: extConstants.COMMAND_PREFIX,
Expand Down
15 changes: 9 additions & 6 deletions vscode/src/commands/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
import { commands, Position, window, Selection, Range, Uri } from "vscode";
import { commands, Position, window, Selection, Range } from "vscode";
import { builtInCommands, extCommands, nbCommands } from "./commands";
import { l10n } from "../localiser";
import * as path from 'path';
import { ICommand } from "./types";
import { LanguageClient } from "vscode-languageclient/node";
import { LOGGER } from '../logger';
import { getContextUri, isNbCommandRegistered, wrapCommandWithProgress } from "./utils";
import { getContextUriFromFile, isNbCommandRegistered, wrapCommandWithProgress } from "./utils";
import { globalState } from "../globalState";
import { FileUtils } from "../utils";

const goToTest = async (ctx: any) => {
let client: LanguageClient = await globalState.getClientPromise().client;
if (await isNbCommandRegistered(nbCommands.goToTest)) {
try {
const res: any = await commands.executeCommand(nbCommands.goToTest, getContextUri(ctx)?.toString());
const res: any = await commands.executeCommand(nbCommands.goToTest, getContextUriFromFile(ctx)?.toString());
if ("errorMessage" in res) {
throw new Error(res.errorMessage);
}
Expand All @@ -39,7 +40,8 @@ const goToTest = async (ctx: any) => {
if (res?.locations?.length) {
if (res.locations.length === 1) {
const { file, offset } = res.locations[0];
const filePath = Uri.parse(file);
// If in the future the GoToTest returns URI locations then pass true as an extra parameter to FileUtils.toUri
const filePath = FileUtils.toUri(file);
const editor = await window.showTextDocument(filePath, { preview: false });
if (offset != -1) {
const pos: Position = editor.document.positionAt(offset);
Expand All @@ -61,7 +63,8 @@ const goToTest = async (ctx: any) => {
});
if (selected) {
for await (const filePath of selected) {
let file = Uri.parse(filePath);
// If in the future the GoToTest returns URI locations then pass true as an extra parameter to FileUtils.toUri
let file = FileUtils.toUri(filePath);
await window.showTextDocument(file, { preview: false });
}
} else {
Expand All @@ -87,7 +90,7 @@ const openStackHandler = async (uri: any, methodName: any, fileName: any, line:
const location: string | undefined = uri ? await commands.executeCommand(nbCommands.resolveStackLocation, uri, methodName, fileName) : undefined;
if (location) {
const lNum = line - 1;
window.showTextDocument(Uri.parse(location), { selection: new Range(new Position(lNum, 0), new Position(lNum, 0)) });
window.showTextDocument(FileUtils.toUri(location, true), { selection: new Range(new Position(lNum, 0), new Position(lNum, 0)) });
} else {
if (methodName) {
const fqn: string = methodName.substring(0, methodName.lastIndexOf('.'));
Expand Down
12 changes: 6 additions & 6 deletions vscode/src/commands/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import * as path from 'path';
import * as fs from 'fs';
import { LOGGER } from '../logger';
import { commands, ConfigurationTarget, Uri, window, workspace } from 'vscode';
import { isError } from '../utils';
import { FileUtils, isError } from '../utils';
import { extCommands, nbCommands } from './commands';
import { ICommand } from './types';
import { LanguageClient } from 'vscode-languageclient/node';
import { globalState } from '../globalState';
import { getContextUri, isNbCommandRegistered } from './utils';
import { getContextUriFromFile, isNbCommandRegistered } from './utils';
import { l10n } from '../localiser';
import { extConstants } from '../constants';
import { Notebook } from '../notebooks/notebook';
Expand All @@ -26,7 +26,7 @@ const createNewNotebook = async (ctx?: any) => {
const activeFilePath = window.activeTextEditor?.document.uri;

if (activeFilePath) {
const parentDir = Uri.parse(path.dirname(activeFilePath.fsPath));
const parentDir = FileUtils.toUri(path.dirname(activeFilePath.fsPath));
if (workspace.getWorkspaceFolder(parentDir)) {
defaultUri = parentDir;
}
Expand All @@ -46,7 +46,7 @@ const createNewNotebook = async (ctx?: any) => {
}
}
if (defaultUri == null) {
defaultUri = Uri.parse(os.homedir());
defaultUri = FileUtils.toUri(os.homedir());
}
}

Expand All @@ -63,7 +63,7 @@ const createNewNotebook = async (ctx?: any) => {
notebookDir = nbFolderPath[0];
}
} else {
notebookDir = getContextUri(ctx) || null;
notebookDir = getContextUriFromFile(ctx) || null;
}
if (notebookDir == null) {
window.showErrorMessage(l10n.value("jdk.notebook.create.error_msg.path.not.selected"));
Expand Down Expand Up @@ -109,7 +109,7 @@ const createNewNotebook = async (ctx?: any) => {

LOGGER.log(`Created notebook at: ${finalNotebookPath}`);

const notebookUri = Uri.file(finalNotebookPath);
const notebookUri = FileUtils.toUri(finalNotebookPath);
const notebookDocument = await workspace.openNotebookDocument(notebookUri);
await window.showNotebookDocument(notebookDocument);
} catch (error) {
Expand Down
5 changes: 3 additions & 2 deletions vscode/src/commands/refactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
import { commands, window, Uri, Range, Location, workspace, Position } from "vscode";
import { commands, window, Range, Location, workspace, Position } from "vscode";
import { ICommand } from "./types";
import { extConstants } from "../constants";
import { builtInCommands, extCommands, nbCommands } from "./commands";
import { l10n } from "../localiser";
import { WorkspaceEdit } from 'vscode-languageserver-protocol';
import { SymbolInformation } from 'vscode-languageclient';
import { globalState } from "../globalState";
import { FileUtils } from "../utils";

const goToSuperImplementationHandler = async () => {
if (window.activeTextEditor?.document.languageId !== extConstants.LANGUAGE_ID) {
Expand All @@ -30,7 +31,7 @@ const goToSuperImplementationHandler = async () => {
const position = window.activeTextEditor.selection.active;
const locations: any[] = await commands.executeCommand(nbCommands.superImpl, uri.toString(), position) || [];
return commands.executeCommand(builtInCommands.goToEditorLocations, window.activeTextEditor.document.uri, position,
locations.map(location => new Location(Uri.parse(location.uri), new Range(location.range.start.line, location.range.start.character, location.range.end.line, location.range.end.character))),
locations.map(location => new Location(FileUtils.toUri(location.uri, true), new Range(location.range.start.line, location.range.start.character, location.range.end.line, location.range.end.character))),
'peek', l10n.value('jdk.extension.error_msg.noSuperImpl'));
}

Expand Down
11 changes: 4 additions & 7 deletions vscode/src/commands/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,17 @@ import { LanguageClient } from "vscode-languageclient/node";
import { l10n } from "../localiser";
import { LOGGER } from "../logger";
import { globalState } from "../globalState";
import { FileUtils, isString } from "../utils";

export const getContextUri = (ctx: any): Uri | undefined => {
export const getContextUriFromFile = (ctx: any): Uri | undefined => {
if (ctx?.fsPath) {
return ctx as Uri;
}
if (ctx?.resourceUri) {
return ctx.resourceUri as Uri;
}
if (typeof ctx == 'string') {
try {
return Uri.parse(ctx, true);
} catch (err) {
return Uri.file(ctx);
}
if (isString(ctx)) {
return FileUtils.toUri(ctx, true);
}

return window.activeTextEditor?.document?.uri;
Expand Down
3 changes: 2 additions & 1 deletion vscode/src/localiser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as l10nLib from '@vscode/l10n'

import * as vscode from 'vscode';
import { extConstants } from './constants';
import { FileUtils } from './utils';

const DEFAULT_LANGAUGE = "en";
const DEFAULT_BUNDLE_FILE = `l10n/bundle.l10n.${DEFAULT_LANGAUGE}.json`;
Expand All @@ -36,7 +37,7 @@ class l10Wrapper implements l10n {
private defaultTranslation: TranslatorFn;

constructor(extensionId: string, defaultBundlePath: string) {
let defaultBundleAbsoluteFsPath = vscode.Uri.file(`${vscode.extensions.getExtension(extensionId)?.extensionPath}/${defaultBundlePath}`).fsPath
let defaultBundleAbsoluteFsPath = FileUtils.toUri(`${vscode.extensions.getExtension(extensionId)?.extensionPath}/${defaultBundlePath}`).fsPath;
l10nLib.config({
fsPath: defaultBundleAbsoluteFsPath
});
Expand Down
4 changes: 2 additions & 2 deletions vscode/src/telemetry/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import * as crypto from 'crypto';
import { Uri, workspace } from 'vscode';
import * as os from 'os';
import { isObject, isString } from '../utils';
import { FileUtils, isObject, isString } from '../utils';

export const getCurrentUTCDateInSeconds = () => {
const date = Date.now();
Expand Down Expand Up @@ -70,7 +70,7 @@ const getUri = (pathOrUri: Uri | string): Uri => {
if (pathOrUri instanceof Uri) {
return pathOrUri;
}
return Uri.file(pathOrUri);
return FileUtils.toUri(pathOrUri);
}

export const getValuesToBeTransformed = (): string[] => {
Expand Down
Loading