Skip to content

Commit b5e6330

Browse files
authored
Start server with -Dfile.encoding=[vscode's file encoding] by default (#790)
Start server with -Dfile.encoding=[vscode file encoding (UTF-8)] by default
1 parent a72a01f commit b5e6330

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/javaServerStarter.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as net from 'net';
44
import * as glob from 'glob';
55
import { StreamInfo, Executable, ExecutableOptions } from 'vscode-languageclient';
66
import { RequirementsData } from './requirements';
7+
import { getJavaEncoding } from './settings';
78

89
declare var v8debug;
910
const DEBUG = (typeof v8debug === 'object') || startedInDebugMode();
@@ -50,6 +51,7 @@ function prepareParams(requirements: RequirementsData, javaConfiguration, worksp
5051
'--add-opens',
5152
'java.base/java.lang=ALL-UNNAMED');
5253
}
54+
5355
params.push('-Declipse.application=org.eclipse.jdt.ls.core.id1',
5456
'-Dosgi.bundles.defaultStartLevel=4',
5557
'-Declipse.product=org.eclipse.jdt.ls.core.product');
@@ -58,6 +60,11 @@ function prepareParams(requirements: RequirementsData, javaConfiguration, worksp
5860
}
5961

6062
let vmargs = javaConfiguration.get('jdt.ls.vmargs', '');
63+
const encodingKey = '-Dfile.encoding=';
64+
if (vmargs.indexOf(encodingKey) < 0) {
65+
params.push(encodingKey + getJavaEncoding());
66+
}
67+
6168
parseVMargs(params, vmargs);
6269
let server_home: string = path.resolve(__dirname, '../server');
6370
let launchersFound: Array<string> = glob.sync('**/plugins/org.eclipse.equinox.launcher_*.jar', { cwd: server_home });

src/settings.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,16 @@ function hasJavaConfigChanged(oldConfig: WorkspaceConfiguration, newConfig: Work
102102
function hasConfigKeyChanged(key, oldConfig, newConfig) {
103103
return oldConfig.get(key) !== newConfig.get(key);
104104
}
105+
106+
export function getJavaEncoding(): string {
107+
const config = workspace.getConfiguration();
108+
const languageConfig = config.get('[java]')
109+
let javaEncoding = null;
110+
if (languageConfig != null) {
111+
javaEncoding = languageConfig['files.encoding'];
112+
}
113+
if (javaEncoding == null) {
114+
javaEncoding = config.get<string>('files.encoding', 'UTF-8');
115+
}
116+
return javaEncoding;
117+
}

0 commit comments

Comments
 (0)