Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable custom server arguments to contain spaces #410

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
42 changes: 40 additions & 2 deletions src/language/dafnyLanguageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function getLanguageServerLaunchArgsNew(): string[] {
};
const verifyOn: string = map[oldVerifyOnValue];

const launchArgs = Configuration.get<string[]>(ConfigurationConstants.LanguageServer.LaunchArgs);
const launchArgs = getCustomLaunchArgs();
const specifiedCores = parseInt(Configuration.get<string>(ConfigurationConstants.LanguageServer.VerificationVirtualCores));
// This is a temporary fix to prevent 0 cores from being used, since the languages server currently does not handle 0 cores correctly: https://github.com/dafny-lang/dafny/pull/3276
const cores = isNaN(specifiedCores) || specifiedCores === 0 ? Math.ceil((os.cpus().length + 1) / 2) : Math.max(1, specifiedCores);
Expand All @@ -41,7 +41,7 @@ function getLanguageServerLaunchArgsNew(): string[] {
}

function getLanguageServerLaunchArgsOld(): string[] {
const launchArgs = Configuration.get<string[]>(ConfigurationConstants.LanguageServer.LaunchArgs);
const launchArgs = getCustomLaunchArgs();
return [
getVerificationArgument(),
getVerifierTimeLimitArgument(),
Expand All @@ -54,6 +54,44 @@ function getLanguageServerLaunchArgsOld(): string[] {
];
}

function getCustomLaunchArgs(): string[] {
const launchArgs = Configuration.get<string[]>(ConfigurationConstants.LanguageServer.LaunchArgs);
return launchArgs.flatMap(a => splitArguments(a));
}

function splitArguments(args: string): string[] {
if(args) {
return [];
}

let inSingleQuote = false;
let inDoubleQuote = false;
const result: string[] = [];
let start = 0;
for(let end = 0; end < args.length; end++) {
let store = false;
if(args[end] === '"' && !inSingleQuote) {
store = inDoubleQuote;
inDoubleQuote = !inDoubleQuote;
}
if(args[end] === '\'' && !inDoubleQuote) {
store = inSingleQuote;
inSingleQuote = !inSingleQuote;
}
if(!inSingleQuote && !inDoubleQuote && args[end] === ' ') {
store = true;
}

if(store) {
result.push(args.substring(start, end - start));
start = end + 1; // Skip the single or double quote or space in the next entry
}
}
result.push(args.substring(start, args.length - start));
return result;
}


function getVerificationArgument(): string {
return `--documents:verify=${Configuration.get<string>(ConfigurationConstants.LanguageServer.AutomaticVerification)}`;
}
Expand Down