Skip to content

Commit 327f006

Browse files
committed
Add auto host from sftp config
1 parent cfaa0cb commit 327f006

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

DEVNOTE.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,7 @@ If error like this happens then you try load Cmake in CLion
109109
```
110110
CMake File API: C:\Users\kWX1061625\work\UTBotCpp\server\cmake-build-debug-remote-host-ml: target-gmock-Debug-0b6fa789e179f468efb4.json: no CMakeLists.txt file at '\utbot_distr\gtest\googlemock\CMakeLists.txt'
111111
```
112-
Settings | Advanced Settings -> "Use legacy generator for CMake 3.20 and higher".
113-
114-
Settings | Build, Execution, Deployment | CMake -> Generator: "Use default"
115-
116-
[issue](https://youtrack.jetbrains.com/issue/CPP-27998)
112+
[check solution in issue](https://youtrack.jetbrains.com/issue/CPP-27998)
117113
118114
119115
### Problems with build in Visual Studio Code

vscode-plugin/src/config/defaultValues.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as vs from 'vscode';
88
import * as vsUtils from '../utils/vscodeUtils';
99
import { Prefs } from './prefs';
1010
import * as pathUtils from '../utils/pathUtils';
11+
import { isIP } from 'net';
1112

1213
export class DefaultConfigValues {
1314
public static readonly DEFAULT_HOST = "127.0.0.1";
@@ -17,19 +18,29 @@ export class DefaultConfigValues {
1718
public static readonly POSSIBLE_TEST_DIR_NAMES = ['test'];
1819

1920
public static getDefaultHost(): string {
20-
return Prefs.getGlobalHost();
21+
var host = Prefs.getGlobalHost();
22+
let sftHost = vsUtils.getFromSftpConfig("host");
23+
if (sftHost && isIP(sftHost)) {
24+
host = sftHost;
25+
}
26+
return host;
2127
}
2228

2329
public static getDefaultPort(): number {
2430
return parseInt(Prefs.getGlobalPort());
2531
}
2632

2733
public static getDefaultRemotePath(): string {
34+
var remotePath = ""
2835
if (Prefs.isRemoteScenario()) {
29-
return vsUtils.getRemotePathFromSftpConfig();
36+
let sftpRemotePath = vsUtils.getFromSftpConfig("remotePath");
37+
if (sftpRemotePath) {
38+
remotePath = sftpRemotePath;
39+
}
3040
} else {
31-
return vsUtils.getProjectDirByOpenedFile().fsPath;
41+
remotePath = vsUtils.getProjectDirByOpenedFile().fsPath;
3242
}
43+
return remotePath;
3344
}
3445

3546
public static async getDefaultBuildDirectoryPath(): Promise<string> {

vscode-plugin/src/utils/pathUtils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as path from 'path';
77
import * as vs from 'vscode';
88
import { Prefs } from '../config/prefs';
99
import * as vsUtils from './vscodeUtils';
10+
import {isWin32} from './utils';
1011

1112
export function substituteRemotePath(localFilePath: string): string {
1213
if (!Prefs.isRemoteScenario()) {
@@ -16,7 +17,7 @@ export function substituteRemotePath(localFilePath: string): string {
1617
const projectDirName = path.basename(vsUtils.getProjectDirByOpenedFile().fsPath);
1718
let remoteFilePath = fsJoin(remoteProjectDirPath,
1819
localFilePath.slice(localFilePath.indexOf(projectDirName) + projectDirName.length));
19-
if (os.platform() === 'win32') {
20+
if (isWin32()) {
2021
remoteFilePath = remoteFilePath.replace(/\\/g, '/');
2122
}
2223
remoteFilePath = normalizeRawPosixPath(remoteFilePath);
@@ -32,7 +33,7 @@ export function substituteLocalPath(remoteFilePath: string): string {
3233
const projectDirName = path.basename(remoteRoot);
3334
const relative = remoteFilePath.slice(remoteFilePath.indexOf(projectDirName) + projectDirName.length);
3435
const localFilePath = fsJoin(root.fsPath, relative);
35-
if (os.platform() === 'win32') {
36+
if (isWin32()) {
3637
return path.win32.normalize(localFilePath);
3738
}
3839
return localFilePath;
@@ -56,7 +57,7 @@ export function getRootPath(): string | undefined {
5657
}
5758

5859
export function fsJoin(...paths: string[]): string {
59-
if (os.platform() === 'win32') {
60+
if (isWin32()) {
6061
return path.win32.join(...paths);
6162
} else {
6263
return path.posix.join(...paths);

vscode-plugin/src/utils/vscodeUtils.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,14 @@ export function getTextEditor(): vs.TextEditor | undefined {
4949
return undefined;
5050
}
5151

52-
export function getRemotePathFromSftpConfig(): string {
52+
export function getFromSftpConfig(param: string): string | undefined {
5353
let workspaceFolder = vs.workspace.workspaceFolders?.[0].uri.fsPath;
5454
if (workspaceFolder) {
5555
let sftpConfigPath = pathUtils.fsJoin(workspaceFolder, '.vscode', 'sftp.json');
5656
if (fs.existsSync(sftpConfigPath)) {
5757
let rawData = fs.readFileSync(sftpConfigPath);
5858
let configJson = JSON.parse(rawData.toString());
59-
if (configJson.remotePath) {
60-
return configJson.remotePath;
61-
}
59+
return configJson[param];
6260
}
6361
}
6462
return "";

0 commit comments

Comments
 (0)