Skip to content

Commit

Permalink
enable semantic diagnostics for script file for misc workspace.
Browse files Browse the repository at this point in the history
now, C#/VB script files in misc workspace will get semantic errors as well as syntax errors.

any language such as F# if document is added to misc workspace with SourceCodeKind.Script, they will automatically get semantic errors as well.

this PR doesn't address changes propagations for #load which was never supported for existing C#/VB script support.
  • Loading branch information
heejaechang committed Nov 29, 2018
1 parent 4a571bd commit 73f242e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ public void RegisterLanguage(Guid languageGuid, string languageName, string scri

internal void StartSolutionCrawler()
{
DiagnosticProvider.Enable(this, DiagnosticProvider.Options.Syntax);
// misc workspace will enable syntax errors and semantic errors for script files for
// all participating projects in the workspace
DiagnosticProvider.Enable(this, DiagnosticProvider.Options.Syntax | DiagnosticProvider.Options.ScriptSemantic);
}

internal void StopSolutionCrawler()
Expand Down Expand Up @@ -352,6 +354,8 @@ private ProjectInfo CreateProjectInfoForDocument(string filePath)
var languageInformation = TryGetLanguageInformation(filePath);
Contract.ThrowIfNull(languageInformation);

var fileExtension = PathUtilities.GetExtension(filePath);

var languageServices = Services.GetLanguageServices(languageInformation.LanguageName);
var compilationOptionsOpt = languageServices.GetService<ICompilationFactoryService>()?.GetDefaultCompilationOptions();

Expand All @@ -361,7 +365,7 @@ private ProjectInfo CreateProjectInfoForDocument(string filePath)

if (parseOptionsOpt != null &&
compilationOptionsOpt != null &&
PathUtilities.GetExtension(filePath) == languageInformation.ScriptExtension)
fileExtension == languageInformation.ScriptExtension)
{
parseOptionsOpt = parseOptionsOpt.WithKind(SourceCodeKind.Script);

Expand Down Expand Up @@ -391,10 +395,11 @@ private ProjectInfo CreateProjectInfoForDocument(string filePath)
var projectId = ProjectId.CreateNewId(debugName: "Miscellaneous Files Project for " + filePath);
var documentId = DocumentId.CreateNewId(projectId, debugName: filePath);

var sourceCodeKind = GetSourceCodeKind();
var documentInfo = DocumentInfo.Create(
documentId,
filePath,
sourceCodeKind: parseOptionsOpt?.Kind ?? SourceCodeKind.Regular,
sourceCodeKind: sourceCodeKind,
loader: new FileTextLoader(filePath, defaultEncoding: null),
filePath: filePath);

Expand All @@ -414,8 +419,19 @@ private ProjectInfo CreateProjectInfoForDocument(string filePath)
metadataReferences: _metadataReferences);

// Miscellaneous files projects are never fully loaded since, by definition, it won't know
// what the full set of information is.
return projectInfo.WithHasAllInformation(hasAllInformation: false);
// what the full set of information is except when the file is script code.
return projectInfo.WithHasAllInformation(hasAllInformation: sourceCodeKind == SourceCodeKind.Script);

SourceCodeKind GetSourceCodeKind()
{
if (parseOptionsOpt != null)
{
return parseOptionsOpt.Kind;
}

return string.Equals(fileExtension, languageInformation.ScriptExtension, StringComparison.OrdinalIgnoreCase) ?
SourceCodeKind.Script : SourceCodeKind.Regular;
}
}

private void DetachFromDocument(uint docCookie, string moniker)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public SourceCodeKind SourceCodeKind
{
get
{
return this.ParseOptions == null ? SourceCodeKind.Regular : this.ParseOptions.Kind;
return this.ParseOptions == null ? this.Attributes.SourceCodeKind : this.ParseOptions.Kind;
}
}

Expand Down

0 comments on commit 73f242e

Please sign in to comment.