Skip to content

Commit

Permalink
Enable custom server arguments to contain spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
keyboardDrummer committed Jul 13, 2023
1 parent 852cd61 commit 87e242d
Showing 1 changed file with 40 additions and 2 deletions.
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

0 comments on commit 87e242d

Please sign in to comment.